Found 6702 Articles for Database

Find out if a varchar contains a percent sign in MySQL?

Ankith Reddy
Updated on 30-Jun-2020 07:31:59

329 Views

To find out a varchar contains a percent sign in MySQL, you can use LIKE operator. The syntax is as follows −SELECT * FROM yourTableName WHERE yourColumnName like '%|%%' escape '|';To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table FindPercentInVarcharDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Words varchar(30),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records with % sign using insert command. The query is as follows −mysql> insert into FindPercentInVarcharDemo(Words) values('This is ... Read More

How to convert DateTime to a number in MySQL?

Arjun Thakur
Updated on 30-Jun-2020 07:33:30

2K+ Views

To convert the date time to a number in MySQL, the syntax is as follows −SELECT UNIX_TIMESTAMP(yourColumnName) as anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DateTimeToNumberDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> releasedDate datetime,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into DateTimeToNumberDemo(releasedDate) values(now()); Query OK, 1 row affected (0.19 sec) mysql> insert into ... Read More

Replace 0 with null in MySQL?

George John
Updated on 30-Jun-2020 07:36:05

2K+ Views

You can use NULLIF() from MySQL to replace 0 with NULL. The syntax is as follows −SELECT *, NULLIF(yourColumnName, 0) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Replace0WithNULLDemo    -> (    -> Id int NOT NULL auto_increment,    -> Name varchar(20),    -> Marks int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.53 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into Replace0WithNULLDemo(Name, Marks) values('John', ... Read More

MySQL date column auto fill with current date?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

13K+ Views

You can use now() with default auto fill and current date and time for this. Later, you can extract the date part using date() function.Case 1:The syntax is as follows:yourDateColumnName date default ‘yourDateValue’;Case 2:The syntax is as follows:yourDateColumnName datetime default now();To understand the above, let us create a table. The query to create a table is as follows:mysql> create table DefaultCurrentdateDemo    -> (    -> LoginDate datetime default now()    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into DefaultCurrentdateDemo values(); Query OK, 1 ... Read More

Find lowest Date (custom) in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

228 Views

To find lowest Date(custom) in MySQL, let us first create a table. The query to create a table is as follows:mysql> create table FindMinimumDate    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> yourDay varchar(2),    -> yourMonth varchar(2),    -> yourYear varchar(4),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into FindMinimumDate(yourDay, yourMonth, yourYear) values('21', '11', '2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into FindMinimumDate(yourDay, yourMonth, yourYear) values('20', '10', '2020'); Query OK, ... Read More

Select distinct combinations from two columns in MySQL?

George John
Updated on 30-Jun-2020 06:53:01

4K+ Views

To select distinct combinations from two columns, you can use CASE statement. Let us create a table with some columns.The query to create a table is as follows −mysql> create table select_DistinctTwoColumns    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> FirstValue char(1),    -> SecondValue char(1),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.57 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into select_DistinctTwoColumns(FirstValue, SecondValue) values('s', 't'); Query OK, 1 row affected (0.12 sec) mysql> insert into select_DistinctTwoColumns(FirstValue, SecondValue) ... Read More

MySQL BETWEEN without the beginning and endpoints?

Chandu yadav
Updated on 30-Jun-2020 06:56:34

49 Views

If you do not want to include start and end value in between, then use the following syntax −SELECT * FROM yourTableName WHERE yourColumnName BETWEEN yourStartingValue and yourEndingValue and    yourColumnName not in (yourStartingValue , yourEndingValue );To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table BetweenWithoutEndPoints    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.54 sec)Now you can insert some records in the table using ... Read More

MySQL BETWEEN without endpoints?

Ankith Reddy
Updated on 30-Jun-2020 07:01:10

152 Views

If you do not want to include the end value in between, then use the following syntax −SELECT * FROM yourTableName WHERE yourColumnName BETWEEN yourStartingValue and yourEndingValue and    yourColumnName not in (yourEndingValue );To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table BetweenWithoutEndPoints    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.54 sec)Now you can insert some records in the table using insert command. The ... Read More

What is the best datatype for currencies in MySQL?

Arjun Thakur
Updated on 30-Jun-2020 07:03:33

141 Views

The best data type for currencies in MySQL is a DECIMAL. The syntax of DECIMAL data type is as follows −DECIMAL(TotalDigit, NumberOfDigitAfterDecimalPoint);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CurrenciesDemo    -> (    -> TotalPrice DECIMAL(10, 2)    -> ); Query OK, 0 rows affected (1.82 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into CurrenciesDemo values(1647575.67); Query OK, 1 row affected (0.19 sec) mysql> insert into CurrenciesDemo values(1647575); Query OK, 1 row affected (0.21 sec) ... Read More

MySQL select * with distinct id?

George John
Updated on 30-Jun-2020 07:06:04

2K+ Views

You can use GROUP BY command for select with distinct id. The syntax is as follows −SELECT *FROM yourTableName GROUP BY yourColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DistinctIdDemo    -> (    -> Id int,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command. Here, we have added ID with duplicate values.The query is as follows −mysql> insert into DistinctIdDemo values(1, 'Mike', 23); Query OK, 1 row ... Read More

Advertisements