Found 4381 Articles for MySQL

MySQL date column auto fill with current date?

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

16K+ 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

299 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

88 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

255 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

198 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

Is `definer` required when creating a MySQL stored procedure?

Chandu yadav
Updated on 30-Jun-2020 07:08:41

2K+ Views

No, definer part is not compulsory when you are creating a stored procedure. It is used when you want to create a definer.Check all the user and host from the MySQL.user table −mysql> select user, host from mysql.user;The following is the output −+------------------+-----------+ | user             | host      | +------------------+-----------+ | Manish           | %         | | User2            | %         | | mysql.infoschema | %         | | mysql.session    | %   ... Read More

Performing a MySQL LIKE comparison on an INT field?

George John
Updated on 30-Jul-2019 22:30:24

729 Views

You need to use cast() method to perform comparison on an INT field. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ......N yourTableName WHERE CAST(yourColumnName as CHAR) LIKE ‘%yourIntegerValue%’;To understand the above syntax, let us create a table. The following is the query to create a table for performing a LIKE comparison on INT field −mysql> create table ComparisonOnIntField    -> (    -> StudentId int NOT NULL,    -> StudentName varchar(20),    -> StudentAge int    -> ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table to perform a MySQL LIKE comparison on an INT ... Read More

MySQL Query a List of Values?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

6K+ Views

To query a list of values, you can use IN operator. The syntax is as follows −SELECT * FROM yourTableName WHERE yourColumnName IN(Value1, Value2, ...N) ORDER BY FIELD(yourColumnName, Value1, Value2, ...N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ListOfValues    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(30),    -> Age int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert ... Read More

Advertisements