AmitDiwan has Published 11365 Articles

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

161 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

380 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

452 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

How to update a MySQL table by swapping two column values?

AmitDiwan

AmitDiwan

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

339 Views

To swap two values in a column, use CASE WHEN statement. Let us first create a table −mysql> create table DemoTable1382    -> (    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1382 ... Read More

How to get the maximum value from a column with alphanumeric strings beginning with specific characters in MYSQL?

AmitDiwan

AmitDiwan

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

515 Views

For maximum value, use MAX() along with CAST() for conversion. Since we want maximum value from string-numbers beginning with specific characters, use RLIKE. Let us first create a table −mysql> create table DemoTable1381    -> (    -> DepartmentId varchar(40)    -> ); Query OK, 0 rows affected (0.48 sec)Insert ... Read More

MySQL UNION SELECT and IN clause in a single query

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 09:37:50

167 Views

Let us first create a table −mysql> create table DemoTable1    -> (    -> StudentId int,    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (1.24 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(210, 'Adam'); Query OK, 1 row affected ... Read More

How can I view cascades in MySQL?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 09:35:27

118 Views

To view cascades, use SHOW CREATE TABLE in MySQL. Let us first create a table −mysql> create table DemoTable1378    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeId varchar(20),    -> EmployeeFirstName varchar(20),    -> EmployeeLastName varchar(20),    -> EmployeeCountryName varchar(40),    -> EmployeeAge ... Read More

How to add a year and two days to a date with a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 11-Nov-2019 09:33:11

109 Views

For this, use INTERVAL in MySQL. Let us first create a table −mysql> create table DemoTable1376    -> (    -> AdmissionDate date    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1376 values('2018-01-21'); Query OK, 1 row ... Read More

Advertisements