AmitDiwan has Published 11365 Articles

MySQL query to fetch the latest date from a table with date records

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:43:19

4K+ Views

Let us first create a table −mysql> create table DemoTable (    DueDate date ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2018-10-01'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2016-12-31'); Query OK, 1 ... Read More

Get maximum date from a list of varchar dates in MySQL

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:40:54

171 Views

Let us first create a table −mysql> create table DemoTable (    AdmissionDate varchar(100) ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Sunday, 11 August 2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Friday, ... Read More

Query to divide the values of two columns and display the result in a new column using MySQL wildcard?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:39:17

240 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value1 int,    Value2 int ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value1, Value2) values(100, 150); Query OK, ... Read More

How do I replace “+”(plus sign) with SPACE in MySQL?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:36:35

376 Views

To replace, use REPLACE() function from MySQL. Let us first create a table −mysql> create table DemoTable (    Number varchar(100) ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('+916578675547'); Query OK, 1 row affected (0.17 sec) mysql> ... Read More

Selecting random entry from MySQL Database?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:34:41

86 Views

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

How to get the 2nd highest value from a table with Student Score?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:32:23

524 Views

To fetch the 2nd highest value, use ORDER BY DESC with LIMIT 1, 1. Let us first create a table −mysql> create table DemoTable (    StudentScore int ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(89); Query ... Read More

How to retrieve the corresponding value for NULL with a MySQL query?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:29:35

60 Views

For this, use IS NULL property. Let us first create a table −mysql> create table DemoTable (    EmployeeName varchar(100),    EmployeeAge int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 32); Query OK, 1 row affected ... Read More

Set a custom value for AUTO_INCREMENT while creating a table and use ZEROFILL. What will happen now when nothing is inserted while using INSERT statement?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:27:36

71 Views

We will see an example and create a table wherein we have set StudentId column as AUTO_INCREMENT = 100 and used ZEROFILL as well −mysql> create table DemoTable (    StudentId int(7) ZEROFILL NOT NULL AUTO_INCREMENT,    PRIMARY KEY(StudentId) )AUTO_INCREMENT=100; Query OK, 0 rows affected (0.48 sec)Insert some records in ... Read More

How to delete fields with values more than a particular value in MySQL?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:22:42

74 Views

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

Format MySQL CURRENT_TIMESTAMP to AM & PM?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:20:27

359 Views

To format, use DATE_FORMAT(). Let us first create a tablemysql> create table DemoTable (    LoginTime time ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('13:10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('20:08'); ... Read More

Advertisements