AmitDiwan has Published 10744 Articles

Implement a MySQL Void Query that does nothing

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:12:28

302 Views

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

Updating last entry of a particular ID in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:11:13

217 Views

To update the last entry of a particular ID in MySQL, use ORDER BY DESC LIMIT 1. This would allow you to update the last entry i.e. row records.Let us first create a table −mysql> create table DemoTable824(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(100),   ... Read More

Retrieve MIN and MAX date in a single MySQL query from a column with date values

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:09:18

4K+ Views

For this, you can use aggregate function MIN() and MAX(). Let us first create a table −mysql> create table DemoTable(AdmissionDate date); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-21'); Query OK, 1 row affected (0.11 sec) mysql> insert ... Read More

ORDER BY specific field value first in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:58:33

394 Views

To order by specific field value first in MySQL, use ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable849(Color varchar(100)); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable849 values('RED'); Query OK, 1 row affected (0.33 ... Read More

Find records with a specific last digit in column with MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:56:39

1K+ Views

For this, use the RIGHT() method to fetch records with a specific last digit. Let us first create a table −mysql> create table DemoTable823(Value varchar(100)); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable823 values('9847826'); Query OK, 1 row affected ... Read More

MySQL SELECT products WHERE 'average price per product' < value?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:55:34

457 Views

Let us first create a table −mysql> create table DemoTable848(    ProductId int,    ProductPrice int ); Query OK, 0 rows affected (1.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable848 values(100, 30); Query OK, 1 row affected (0.57 sec) mysql> insert into DemoTable848 values(101, ... Read More

ORDER BY a specific word in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:53:51

458 Views

For this, use ORDER BY INSTR(). Let us first create a table −mysql> create table DemoTable822(Word text); Query OK, 0 rows affected (1.11 sec)Insert some records in the table using insert command −mysql> insert into DemoTable822 values('Forever'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable822 values('ever'); Query ... Read More

MySQL query to exclude values having specific last 3 digits

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:52:11

274 Views

For this, use NOT IN. Let us first create a table −mysql> create table DemoTable(Value int); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1234); Query OK, 1 row affected (0.54 sec) mysql> insert into DemoTable values(2345); Query OK, ... Read More

MySQL query to set current date in the datetime field for all the column values

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:50:26

175 Views

Let us first create a table −mysql> create table DemoTable821(AdmissionDate datetime); Query OK, 0 rows affected (1.24 sec)Insert some records in the table using insert command −mysql> insert into DemoTable821 values('2019-01-21'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable821 values('2018-11-02'); Query OK, 1 row affected (0.10 sec) ... Read More

How to limit records to only the last five results in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:48:13

316 Views

To fetch only the last five records below is the syntax −select *from yourTableName order by yourColumnName DESC LIMIT 5;Let us first create a table −mysql> create table DemoTable820(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records ... Read More

Advertisements