AmitDiwan has Published 10744 Articles

How to make 'from' as column name in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:11:46

571 Views

Use the backticks symbol to consider ‘from’ as column name since it is a reserved word. We will now create a table with from reserved word surrounded by backtick −mysql> create table DemoTable1810      (      `from` varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert ... Read More

Fetch a specific column value (name) in MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:10:32

863 Views

To fetch a specific column value, use LIKE clause. Let us first create a table −mysql> create table DemoTable1809      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1809 values('John'); Query ... Read More

Display all the column values in a single row separated by comma in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:08:19

1K+ Views

For this, use GROUP_CONCAT() and CONCAT(). Let us first create a table −mysql> create table DemoTable1807      (      Id int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1807 values(101); Query OK, 1 row ... Read More

How to select rows in MySQL that are >= 1 DAY from the current date?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:07:05

867 Views

To get data greater than equal to 1 day from the current date, use the concept of INTERVAL in MySQL.The current date is as follows −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-11-29 | +------------+ 1 row in set (0.00 sec)We will first create a table −mysql> create ... Read More

MySQL query to update only a single field in place of NULL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:06:12

184 Views

For this, you can use COALESCE(). Let us first create a table −mysql> create table DemoTable1805      (      Name1 varchar(20),      Name2 varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1805 values('Chris', ... Read More

MySQL rows concatenation to fetch maximum corresponding value from duplicate IDs?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:03:39

132 Views

For this, you can use GROUP BY clause. To find maximum value, use MAX() function. Let us first create a table −mysql> create table DemoTable1804      (      Id int,      Marks1 int,      Marks2 int,      Marks3 int      ); Query OK, 0 ... Read More

How to use CONTAINS() with CURDATE in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:03:28

210 Views

For this, you can use CONCAT() with CURDATE().There is no function with the name CONTAINS() in MySQL.Let us first get the current date. The current date is as follows −mysql> select curdate();This will produce the following output −+------------+ | curdate()  | +------------+ | 2019-11-28 | +------------+ 1 row in set ... Read More

MySQL group by for separate id without using GROUP BY to remove duplicate column row?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 05:59:27

142 Views

For this, you can use DISTINCT keyword. Let us first create a table −mysql> create table DemoTable1801      (      Name varchar(20),      Score int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1801 ... Read More

Find sum with MySQL SUM() and give aliases for column heading

AmitDiwan

AmitDiwan

Updated on 23-Dec-2019 12:10:58

532 Views

For alias, use the following syntax wherein we are display an alias name −select sum(yourColumnName) as anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable1800      (      Salary int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table ... Read More

How to quote values of single column using GROUP_CONCAT and CONCAT with DISTINCT in MySQL?

AmitDiwan

AmitDiwan

Updated on 23-Dec-2019 12:09:34

498 Views

For this, you can use group_concat() along with replace(). Let us first create a table −mysql> create table DemoTable1799      (      EmployeeId varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1799 values('101, 102, ... Read More

Advertisements