AmitDiwan has Published 10744 Articles

How do you get whether a column is a primary key in MySQL?

AmitDiwan

AmitDiwan

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

454 Views

To get whether a column is a primary key, use COLUMN_NAME and COLUMN_KEY='PRI'. With that, the entire syntax is as follows −select column_name, case when column_key= 'PRI' then 'yourMessage1' else ''yourMessage2' end as anyAliasName from information_schema.columns where table_schema =database() and `table_name` = yourTableName order by `table_name`, ordinal_position;To understand the above ... Read More

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

AmitDiwan

AmitDiwan

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

596 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

262 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

231 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

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

Place a specific value for NULL values in a MySQL column

AmitDiwan

AmitDiwan

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

213 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

615 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

411 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

Advertisements