Found 4378 Articles for MySQL

How to use comparison operator for numeric string in MySQL?

AmitDiwan
Updated on 25-Feb-2020 12:23:34

75 Views

To use comparison operator for numeric string, use the substring() method. Let us first create a table −mysql> create table DemoTable1881    (    UserId int,    UserEducationGap varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1881 values(101, '5-9'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1881 values(102, '2-4'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1881 values(103, '4-8'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1881 values(104, '7-12'); Query OK, 1 row affected (0.00 sec)Display all records ... Read More

How to copy rows from one table to another in MySQL?

AmitDiwan
Updated on 27-Dec-2019 06:29:45

3K+ Views

For this, use INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1879    (    Id int,    Name varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1879 values(101, 'Chris Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1879 values(102, 'David Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1879 values(103, 'Adam Smith'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1879;This will produce the ... Read More

Place a specific value for NULL values in a MySQL column

AmitDiwan
Updated on 27-Dec-2019 06:27:51

145 Views

Use IFNULL() to find and place a specific value for NULL values. Let us first create a table −mysql> create table DemoTable1878    (    FirstName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1878 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1878 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1878 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1878 values(NULL); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement ... Read More

How to select a date less than the current date with MySQL?

AmitDiwan
Updated on 27-Dec-2019 06:25:41

4K+ Views

Let us first create a table −mysql> create table DemoTable1877 ( DueDate datetime ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1877 values('2019-12-10'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1877 values('2019-12-05'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1877 values('2019-12-07'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1877 values('2019-12-09'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1877;This will ... Read More

Select minimum row value from a column with corresponding duplicate column values in MySQL

AmitDiwan
Updated on 27-Dec-2019 06:18:03

476 Views

Let us first create a table −mysql> create table DemoTable1875    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Class varchar(20),    Amount int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1875(Class, Amount) values('X', 750); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class, Amount) values('X', 140); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class, Amount) values('X', 450); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class, Amount) values('Y', 6780); Query OK, 1 row affected (0.00 ... Read More

Insert Euro and Dollar symbol to a column in MySQL?

AmitDiwan
Updated on 27-Dec-2019 06:15:28

1K+ Views

For this, use CASE statement with UPDATE command. Let us first create a table −mysql> create table DemoTable1874    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Amount varchar(100) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1874(Amount) values('3450'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('190'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('7600'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('4500'); Query OK, 1 row affected (0.00 sec)Display all records ... Read More

Best way to update a single column in a MySQL table?

AmitDiwan
Updated on 27-Dec-2019 06:11:45

323 Views

To update a single column, use UPDATE and SET as in the below syntax −update yourTableName set yourColumnName=yourValue;Let us first create a table −mysql> create table DemoTable1873      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      FirstName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1873(FirstName) values('John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1873(FirstName) values('Adam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1873(FirstName) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... Read More

MySQL query to SELECT rows with LIKE and create new column containing the matched string?

AmitDiwan
Updated on 27-Dec-2019 06:09:28

205 Views

For this, use SUBSTRING(). Let us first create a table −mysql> create table DemoTable1872    (    Name varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1872 values('John Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1872 values('Adam Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1872 values('Mitchell Johnson'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1872;This will produce the following output −+------------------+ | Name         ... Read More

MySQL Datetime to add days?

AmitDiwan
Updated on 27-Dec-2019 06:05:40

176 Views

Let us first create a table −mysql> create table DemoTable1871      (      ArrivalDate datetime      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1871 values('2019-12-19 7:45:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1871 values('2018-11-10 12:00:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1871 values('2019-01-31'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1871; This will produce the following output −+---------------------+ | ArrivalDate         | ... Read More

Get first date from timestamp in MySQL group by another column with duplicate value

AmitDiwan
Updated on 27-Dec-2019 06:04:31

238 Views

For this, you can use aggregate function MIN() and GROUP BY. Let us first create a table −mysql> create table DemoTable1870      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      Value int,      ShippingTimestamp varchar(100)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(10, '1570645800'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(10, '1546194600'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(11, '1573324200'); Query OK, 1 row affected (0.00 ... Read More

Advertisements