AmitDiwan has Published 10740 Articles

Display all products having the highest amount in a MySQL table with product details?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:53:23

487 Views

Use MAX() along with subquery for this Here, MAX() is used to get the maximum amount. Let us first create a table −mysql> create table DemoTable (    ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ProductName varchar(100),    ProductAmount int ); Query OK, 0 rows affected (0.53 sec)Insert some ... Read More

How to compare the first date and the last date from a MySQL column with date records?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:49:45

360 Views

To compare the first date with the last date, use TIME_TO_SEC() along with MAX() and MIN(). Let us first create a table −mysql> create table DemoTable (    UserName varchar(100),    UserPostDatetime datetime ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> ... Read More

How to get multiple rows in a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:48:08

793 Views

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

Can we use WHERE clause inside MySQL CASE statement?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:46:16

334 Views

For this, use the CASE WHEN statement. Let us first create a table −mysql> create table DemoTable1040 (    Value1 int,    Value2 int,    Value3 int ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1040 values(10, 30, 1); ... Read More

How to get left substring in MySQL from a column with file path? Display the entire file path string excluding the file name?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:39:52

411 Views

To get the left substring, use LEFT() along with substring_index(). For example, let’s say the file path is −“/MyFile/JavaProgram/Hello.java “Here, we will see how to display the entire file path except for the file name i.e. −/MyFile/JavaProgram/Let us first create a table −mysql> create table DemoTable (    FileLocation text ... Read More

How to get the fourth highest value using MySQL query?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:30:53

355 Views

To get the fourth-highest value, use LIMIT OFFSET along with ORDER BY. Let us first create a table −mysql> create table DemoTable (    Amount int ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(980); Query OK, 1 ... Read More

Add a column count in a MySQL query on the basis of last name records?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:29:38

455 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName) values('David', 'Miller'); Query OK, ... Read More

How to suppress warnings in MySQL?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:27:00

4K+ Views

To suppress warnings, set SQL_NOTES=0. Let us see an example.At first, we will set SQL_NOTES to 1 −mysql> SET sql_notes = 1; Query OK, 0 rows affected (0.00 sec)Now, let us drop a table which does not exist. As you can see a warning message is now visible −mysql> drop ... Read More

Sort values that contain letters and symbols in custom order with MySQL

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:25:28

214 Views

For custom order, use ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable (    Title varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Java_1+'); Query OK, 1 row affected (0.14 sec) mysql> ... Read More

MySQL query to display records on the basis of conditions IS NULL OR !=1;?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:23:28

123 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100),    Score int ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Score) values('John', 45); Query OK, ... Read More

Advertisements