AmitDiwan has Published 10744 Articles

How can I select rows which fall on a specific day of week in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:31:15

203 Views

For specific day of week, use DAYOFWEEK().Let us first create a table −mysql> create table DemoTable785 ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(100), ShoppingDate date ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table ... Read More

MySQL query to sort column values and ignoring quotes on one of the values

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:16:48

218 Views

To ignore quotes while ordering column values, use ORDER BY TRIM().Let us first create a table −mysql> create table DemoTable784 ( Message varchar(100) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable784 values('Good'); Query OK, 1 ... Read More

Count and sort rows with a single MySQL query

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:14:30

211 Views

Let us first create a table −mysql> create table DemoTable783 ( FirstName varchar(100) ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable783 values('Adam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable783 values('Chris'); Query ... Read More

MySQL query to group by column and display the sum of similar values in another column

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:12:49

514 Views

For this, use GROUP BY HAVING clause.Let us first create a table −mysql> create table DemoTable782 ( Name varchar(100), Score int ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command −mysql> insert into DemoTable782 values('John', 156); Query ... Read More

Find the count of EMPTY or NULL columns in a MySQL table?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:10:53

1K+ Views

Let us first create a table −mysql> create table DemoTable781 ( Name varchar(100) ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable781 values('Chris'); Query ... Read More

How to display the column names from a table excluding some in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:09:06

367 Views

To exclude some of the column names, use NOT IN.Let us first create a table −mysql> create table DemoTable780 (    CustomerId int,    CustomerName varchar(100),    CustomerAge int, CustomerCountryName varchar(100), isMarried tinyint(1) ); Query OK, 0 rows affected (0.47 sec)Here is the query ... Read More

Increment column value ‘ADD’ with MySQL SET clause

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:06:27

210 Views

Since the column value ‘ADD’ is already a reserved word, therefore you need to use backticks around the word ADD like `ADD`.Let us see an example and create a table −mysql> create table DemoTable779 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, `ADD` int ... Read More

Select rows from a MySQL table and display using IN()

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:04:43

244 Views

Let us first create a table −mysql> create table DemoTable778 ( ClientId varchar(100), ClientName varchar(100) ); Query OK, 0 rows affected (1.05 sec)Insert some records in the table using insert command −mysql> insert into DemoTable778 values('J-101', 'John'); Query OK, 1 row affected (0.20 sec) ... Read More

MySQL query to display the column and its values using OR in WHERE statement

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:02:13

88 Views

Let us first create a table −mysql> create table DemoTable777 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAge int ); Query OK, 0 rows affected (1.34 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Why does the following error occur in MySQL: ERROR 1062 (23000): Duplicate entry?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 07:59:17

3K+ Views

Let’s say you have set column values as unique key and try to insert duplicate values in the table. This will lead to ERROR 1062 (23000): Duplicate entry.Let us first create a table -mysql> create table DemoTable776 (    FirstValue int,    SecondValue int,    unique key(FirstValue, SecondValue) ); Query ... Read More

Advertisements