Found 4378 Articles for MySQL

MySQL ORDER BY with EXPLAIN command

AmitDiwan
Updated on 22-Aug-2019 13:02:12

86 Views

Let us first create a table −mysql> create table DemoTable606 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100)); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable606(FirstName) values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable606(FirstName) values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable606(FirstName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable606(FirstName) values('David'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable606;This will produce the following output −+----+-----------+ ... Read More

Format date to display month names with the entire date in MySQL?

AmitDiwan
Updated on 22-Aug-2019 12:57:43

101 Views

For this, you can use DATE_FORMAT(). Let us first create a table −mysql> create table DemoTable605 (DueDate date); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable605 values('2019-01-21'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable605 values('2019-02-23'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable605 values(curdate()); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable605;This will produce the following output −+------------+ | DueDate    | +------------+ | 2019-01-21 | | 2019-02-23 | | 2019-03-04 ... Read More

Comma separated argument applicable for IN operator in MySQL?

AmitDiwan
Updated on 02-Jul-2020 11:32:42

138 Views

Use FIND_IN_SET() for command separated argument. Let us first create a table −mysql> create table DemoTable604 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Title varchar(100)); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable604(Title) values('MySQL'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable604(Title) values('C++'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable604(Title) values('MongoDB'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable604(Title) values('Java'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable604;This ... Read More

How to find the name of a column in MySQL?

AmitDiwan
Updated on 22-Aug-2019 12:48:51

3K+ Views

For this, you can use SHOW COLUMNS or INFORMATION_SCHEMA.COLUMN.Let us first create a table −mysql> create table DemoTable603    (       ClientId int NOT NULL AUTO_INCREMENT,       ClientName varchar(100),       ClientAge int,       ClientAddress varchar(100),       ClientCountryName varchar(100),       ClientEducationDetails varchar(200),       PRIMARY KEY(ClientId)    ); Query OK, 0 rows affected (0.59 sec)CASE 1 − Using SHOW commandHere is the query to find the name of a column in MySQL −mysql> SHOW COLUMNS FROM DemoTable603;This will produce the following output −+------------------------+--------------+------+-----+---------+----------------+ | Field           ... Read More

MySQL Quoted table/field names vs unquoted names?

AmitDiwan
Updated on 22-Aug-2019 12:40:38

135 Views

Any identifiers like tablename, stored procedure, viewname or column etc. may be quoted or unquoted. When an identifier is a reserved keyword then you must quote it, else an error would occur.Let us first create a table. Here, we have taken field names as reserved keywords −mysql> create table `INT` (`select` int, `varchar` varchar(100)); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into `INT` values(1, 'MySQL'); Query OK, 1 row affected (0.14 sec) mysql> insert into `INT` values(2, 'MongoDB'); Query OK, 1 row affected (0.34 sec) mysql> insert into `INT` values(3, ... Read More

Perform MySQL ORDER BY keyword match?

AmitDiwan
Updated on 22-Aug-2019 12:33:34

102 Views

For this, let us create a table, insert some values and use ORDER BY CASE. Let us first create a table −mysql> create table DemoTable602 (GameName text); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable602 values('Candy cash game'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable602 values('Pubg'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable602 values('cash Candy game'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable602 values('subway'); Query OK, 1 row affected (0.14 sec)Display all records from the table using ... Read More

Retrieve records whenever a column value starts with 2 vowel letters in MySQL

AmitDiwan
Updated on 22-Aug-2019 12:30:19

80 Views

Let us first create a table −mysql> create table DemoTable664 (CityName varchar(100)); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable664 values('Springfield'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable664 values('Austin'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable664 values('Franklin'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable664 values('OAKLAND'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable664 values('Anchorage'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable664;This will ... Read More

Enum with NOT NULL in a MySQL field?

AmitDiwan
Updated on 22-Aug-2019 12:23:40

693 Views

In ENUM data type, if you do not declare NOT NULL then it gives the default value NULL. However, if you declare NOT NULL then it gives the first value from the ENUM.CASE 1 −When the ENUM gives NULL value. Let us first create a table:mysql> create table DemoTable1(isMarried ENUM('YES', 'NO')); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+-----------+ | isMarried | +-----------+ ... Read More

How to separate last name and first names in single column into two new columns in MySQL?

AmitDiwan
Updated on 22-Aug-2019 12:19:39

2K+ Views

For this, use SUBSTRING_INDEX() and REPLACE(). Let us first create a table −mysql> create table DemoTable (Name varchar(100)); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command. Here, we have inserted last name and first names −mysql> insert into DemoTable values('Chris | Bob Brown'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Carol | Robert Taylor'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Sam | David Miller'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will ... Read More

Best way to combine multiple advanced MySQL select queries?

AmitDiwan
Updated on 22-Aug-2019 12:13:50

322 Views

To combine multiple advanced MySQL select queries, use UNION. Let us first create a table −mysql> create table DemoTable1 (Value1 int, Value2 int); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10, 29); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1 values(100, 190); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1 values(40, 101); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+--------+--------+ | Value1 | Value2 | ... Read More

Advertisements