Sharon Christine has Published 337 Articles

MySQL query to create table dynamically?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:36:25

2K+ Views

For this, you can use stored procedure. Let us create a table dynamically with two columns i.e. StudentId as int, whereas StudentName as varchar −mysql> DELIMITER $$ mysql> CREATE PROCEDURE creatingDynamicTableDemo(yourTableName VARCHAR(200))    -> BEGIN    ->    SET @name = yourTableName;    ->    SET @st = CONCAT('   ... Read More

MySQL query with two boolean conditions to extract date based on hour?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:24:50

185 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> AdmissionDate datetime    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-10 10:45:10'); Query OK, 1 row affected (0.30 sec) mysql> ... Read More

How do I select 5 random rows from the 20 most recent rows in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:22:49

540 Views

For random, use RAND() method. And for limit on rows, use the LIMIT() method.Let us first create a table −mysql> create table DemoTable    -> (    -> ShippingDate datetime    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert ... Read More

How to get everything before the last occurrence of a character in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:55:53

730 Views

You can use below syntax. Following is the syntax −update yourTableName set yourColumnName=REVERSE(SUBSTRING(REVERSE(yourColumnName), INSTR(REVERSE(yourColumnName), '.')));Let us first create a table −mysql> create table DemoTable -> ( -> Words text -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

How to update data in a MySQL database without removing the old data?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:39:56

1K+ Views

For this, you can use UPDATE and concatenate the new data with the old one to save the old data as well −update yourTableName set yourColumnName=concat(yourColumnName, ", yourValue");Let us first create a table −mysql> create table DemoTable -> ( -> CustomerName varchar(100) -> ); Query OK, 0 rows affected (0.54 ... Read More

MySQL query to return the entire date and time based on a string and format

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:36:03

147 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> AdmissionDate varchar(100)    -> ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Wed, 19 Jun 2019 04:10:20'); Query OK, 1 row affected (0.22 ... Read More

Create a table named “select” in SQL databases?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:32:59

202 Views

Since “select” is a reserved word in MySQL, we cannot create a table name with it. But, if you still want to create such a table, surround the word select with quote.Let us first create a table −mysql> create table `select` -> ( -> Number int -> ); Query OK, ... Read More

How to order an alphanumeric column in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:16:32

1K+ Views

To order an alphanumeric column with values like “100X, “2Z”, etc. use the ORDER BY. Let us first create a table −mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

How to place number 0 from a column at the end maintaining the ascending search order in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:13:44

132 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Number int    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.13 sec) mysql> insert ... Read More

Fix Error with TYPE=HEAP for temporary tables in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:11:41

303 Views

The TYPE=HEAP deprecated in newer MySQL versions. You can use ENGINE=HEAP instead of TYPE. Following is the syntax −ENGINE=HEAP;Let us first create a table. Here, we have set Engine=HEAP −mysql> create TEMPORARY table DemoTable    -> (    -> StudentId int,    -> StudentName varchar(30)    -> )Engine = HEAP; ... Read More

Previous 1 ... 5 6 7 8 9 ... 34 Next
Advertisements