AmitDiwan has Published 10740 Articles

How to select row when column must satisfy multiple value in MySQL?

AmitDiwan

AmitDiwan

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

620 Views

For this, you can use GROUP BY HAVING clause along with IN(). Let us first create a table −mysql> create table DemoTable1885    (    FirstName varchar(20),    Subject varchar(50)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

MySQL IF/WHEN/ELSE/OR with ORDER BY FIELD

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:37:06

279 Views

Let us first create a table −mysql> create table DemoTable1884    (    Marks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1884 values(55); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1884 values(97); Query ... Read More

Can we use a comma between MySQL SELECT statements?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:34:22

264 Views

Yes, we can do that. The syntaxes are as follows −Syntax1: select * from yourTableName1, yourTableName2; Syntax2: select * from yourTableName1 cross join yourTableName2;Both the above syntaxes give the same result.Let us first create a table −mysql> create table DemoTable1882    (    Id int    ); Query OK, 0 ... Read More

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

AmitDiwan

AmitDiwan

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

4K+ 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 ... Read More

Place a specific value for NULL values in a MySQL column

AmitDiwan

AmitDiwan

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

235 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 ... Read More

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

AmitDiwan

AmitDiwan

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

5K+ 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) ... Read More

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

AmitDiwan

AmitDiwan

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

632 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) ... Read More

Insert Euro and Dollar symbol to a column in MySQL?

AmitDiwan

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 ... Read More

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

AmitDiwan

AmitDiwan

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

426 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 ... Read More

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

AmitDiwan

AmitDiwan

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

309 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> ... Read More

Advertisements