AmitDiwan has Published 10740 Articles

How to check if any of the strings in a column contains a specific string in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:41:16

2K+ Views

For this, use CONCAT() along with LIKE operator. Let us first create a table −mysql> create table DemoTable (    Name varchar(40) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.33 sec) ... Read More

Perform NAND/NOR operations in MySQL

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:38:33

1K+ Views

Let us first see how we can perform NAND/NOR operations in MySQL. The concept is as follows −NAND= NOT( yourColumnName1 AND yourColumnName2) NOR=NOT( yourColumnName1 OR yourColumnName2)Let us first create a table −mysql> create table DemoTable (    Value1 boolean ,    Value2 boolean ); Query OK, 0 rows affected (0.72 ... Read More

Display records from the current date till rest of the same month in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:35:40

155 Views

Let us first create a table −mysql> create table DemoTable (    BookingDate date ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-09-21'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2018-09-10'); Query OK, 1 ... Read More

MySQL query to group by names and display the count in a new column

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:33:24

816 Views

Use GROUP BY with the COUNT() method. Group the names with GROUP BY and count using the COUNT() method. Let us first create a table −mysql> create table DemoTable (    Name varchar(30) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> ... Read More

Need to populate autocomplete with records on the basis of first and last name of schools in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:30:14

105 Views

To populate autocomplete, use the LIKE clause in MySQL. Let us first create a table −mysql> create table DemoTable (    SchoolName varchar(100) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Horce Greeley'); Query OK, 1 row affected ... Read More

Group by one column and display corresponding records from another column with a separator in MySQL

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:28:07

1K+ Views

For this, use GROUP_CONCAT() along with GROUP BY. Here, the GROUP_CONCAT() is used to concatenate data from multiple rows into one field.Let us first create a table −mysql> create table DemoTable (    PlayerId int,    ListOfPlayerName varchar(30) ); Query OK, 0 rows affected (0.52 sec)Insert some records in the ... Read More

Display NULL and NOT NULL records except a single specific value in MySQL

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 13:04:54

223 Views

To display NULL records, use IS NULL in MySQL. To ignore a single value, use the != operator , which is an alias of the operator.Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    PlayerName varchar(40) ); Query ... Read More

MySQL throws an error when the table name “match” is not surrounded by single quotes?

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 13:02:44

221 Views

Do not use single quotes. You need to use backticks around the table name match, since it is a reserved name in MySQL. Following is the error that occurs :mysql> select *from match; ERROR 1064 (42000) : You have an error in your SQL syntax; check the manual that corresponds ... Read More

Fix MySQL ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 12:56:00

13K+ Views

To fix this error, you need to add PRIMARY KEY to auto_increment field. Let us now see how this error occurs −Here, we are creating a table and it gives the same error −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT,    StudentName varchar(40),    StudentAge int ... Read More

Get Nth weekday of the month from a column with DATE records in MySQL

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 12:51:19

340 Views

We need to find the weekday i.e. week 1 from date 1 to 7, week 2 from date 8 to 14, etc. To get the day, use DAY() function in MySQL. Set the conditions to get the weekday (number) using CASE statement.Let us now see an example and create a ... Read More

Advertisements