AmitDiwan has Published 10744 Articles

MySQL query to fetch date more recent than 14 days?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:28:09

860 Views

Let us first create a −mysql> create table DemoTable1392    -> (    -> ArrivalDate  date    -> ); Query OK, 0 rows affected (0.43 sec)Insert some records in the table using insert −mysql> insert into DemoTable1392 values('2019-09-10'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable1392 values('2019-09-26'); ... Read More

Fix error in MySQL “select ClientId,ClientName,ClientAge, from tablename”

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:26:58

180 Views

The error occurs because we have a comma at the end of the column names, just before “from tablename’. Here is the error you may have got −mysql> select ClientId, ClientName, ClientAge, from DemoTable1391; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds ... Read More

MySQL automatic string to integer casting in WHERE clause to fetch a specific id

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:24:11

588 Views

If the string begins with integer then it converts the string to integer, otherwise it won’t. Let us first create a −mysql> create table DemoTable1390    -> (    -> StudentId varchar(20)    -> ); Query OK, 0 rows affected (0.93 sec)Insert some records in the table using insert −mysql> ... Read More

Make all column names lower case in MySQL with a single query

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:20:59

1K+ Views

Let us first create a −mysql> create table DemoTable1    -> (    -> StudentFirstName varchar(20),    -> StudentLastName varchar(20),    -> StudentAge int,    -> StudentCountryName varchar(20)    -> ); Query OK, 0 rows affected (4.20 sec)Let us now make all column names lower case in MySQL −mysql> select ... Read More

Find exact string value with COLLATE in MySQL?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:18:56

156 Views

Let us first create a −mysql> create table DemoTable1620    -> (    -> Subject varchar(20)    -> ); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert −mysql> insert into DemoTable1620 values('mysql'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1620 values('MySql'); ... Read More

How to select multiple max values which would be duplicate values as well in MYSQL?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:17:48

2K+ Views

For this, use the join concept. Let us first create a −mysql> create table DemoTable1389    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentMarks int    -> ); Query OK, 0 rows affected (2.73 sec)Insert some records in the table using insert command. Here, ... Read More

Display the contents of a VIEW in MySQL?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:15:27

1K+ Views

Following is the syntax −select * from yourViewName;Let us first create a table −mysql> create table DemoTable1388    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(40)    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert ... Read More

How to obtain multiple rows in a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:11:54

248 Views

To obtain multiple rows in a single MySQL query, use LIKE operator. Let us first create a table −mysql> create table DemoTable1385    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.90 sec)Insert some records ... Read More

Insert multiple rows in a single MySQL query

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:10:16

488 Views

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

MySQL query to find the top two highest scores

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 10:08:17

556 Views

For this, use aggregate function MAX(). Let us first create a table −mysql> create table DemoTable1383    -> (    -> Id int,    -> PlayerScore int    -> ); Query OK, 0 rows affected (0.90 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1383 values(200, ... Read More

Advertisements