Found 6705 Articles for Database

MySQL query to remove first digit?

AmitDiwan
Updated on 22-Aug-2019 13:05:05

788 Views

For this, use SUBSTR(). Following is the syntax −update yourTableName set yourColumnName=substr(yourColumnName, 2);Let us first create a table −mysql> create table DemoTable607 (Value varchar(100)); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable607 values('83967364'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable607 values('10939432'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable607 values('932111'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable607;This will produce the following output −+----------+ | Value    | +----------+ | 83967364 ... Read More

MySQL ORDER BY with EXPLAIN command

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

154 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

146 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

244 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

202 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

162 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

119 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?

Venu Madhavi
Updated on 22-Jan-2025 18:09:37

978 Views

In MySQL, the ENUM is a data type that is used to create a column with a fixed set of values. It is helpful for the fields that have limited alternatives, such as categories, statuses, and color codes. In the ENUM data type, if you do not declare NOT NULL then it gives the default value NULL or Empty String('') when inserting records without specifying a value. However, if you declare NOT NULL and don't specify the values when inserting then it gives the first value from the ENUM. Following is the syntax to create a table that has ... 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

3K+ 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

Advertisements