AmitDiwan has Published 8358 Articles

What would happen if we run SELECT WHERE columnName = zero in MySQL?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:21:35

136 Views

The following syntax will fetch all the values from the column −select * from yourTableName where yourColumnName=0;Let us first create a table −mysql> create table DemoTable1791      (      FirstName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert ... Read More

MySQL query to fetch records from a range of months?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:19:16

213 Views

Let us first create a table −mysql> create table DemoTable1795      (      Name varchar(20),      DueDate date      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1795 values('John', '2018-07-21'); Query OK, 1 row affected ... Read More

How to auto increment with 1 after deleting data from a MySQL table?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:18:07

806 Views

For this, you can use TRUNCATE TABLE command. Let us first create a table −mysql> create table DemoTable1796      (      StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,      StudentName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using ... Read More

UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:12:18

337 Views

For this, you can use STR_TO_DATE(), since we have date records in the following format: 21/11/2019.Let us first create a table −mysql> create table DemoTable1808      (      AdmissionDate varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command ... Read More

Update MySQL table column by matching date using date() function?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:08:00

533 Views

Following is the syntax to match date with date() function and updating a column −update yourTableName set yourColumnName=yourValue where date(yourColumnName)=curdate();Let us first create a table −mysql> create table DemoTable1816      (      Name varchar(20),      JoiningDate datetime      ); Query OK, 0 rows affected (0.00 sec)Insert ... Read More

Fetch how many people are registering on the current date with MySQL

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:06:28

227 Views

For this, you can use COUNT() along with GROUP BY MONTH(). To match with the current date, use CURRENT_DATE(). The current date is as follows −mysql> select curdate() ; +------------+ | curdate()  | +------------+ | 2019-11-30 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> ... Read More

Check for NULL or empty variable in a MySQL stored procedure

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:02:51

6K+ Views

To check for NULL or empty variable, use the IF condition. Let us create a stored procedure −mysql> delimiter // mysql> create procedure checkingForNullDemo(Name varchar(20))      begin      if Name is NULL OR Name='' then      select 'Adam Smith';      else      select Name;   ... Read More

How to use comparison operator for numeric string in MySQL?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 12:23:34

140 Views

To use comparison operator for numeric string, use the substring() method. Let us first create a table −mysql> create table DemoTable1881    (    UserId int,    UserEducationGap varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1881 ... Read More

Insert NULL value into database field with char(2) as type in MySQL?

AmitDiwan

AmitDiwan

Updated on 21-Jan-2020 12:21:27

357 Views

Let us first create a table −mysql> create table DemoTable658(FirstName varchar(100), value char(2)); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable658(FirstName) values('John') ; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable658(value, FirstName) values(default(value), 'Sam'); Query OK, ... Read More

Query non-empty values of a row first in ascending order and then display NULL values

AmitDiwan

AmitDiwan

Updated on 21-Jan-2020 12:19:53

192 Views

For this, use ORDER BY ISNULL(). Let us first create a table −mysql> create table DemoTable669 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentScore int ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable669(StudentScore) values(45) ; ... Read More

Advertisements