Found 4381 Articles for MySQL

How to correctly convert a date format into a MySQL date?

karthikeya Boyini
Updated on 30-Jun-2020 12:29:31

275 Views

Use the STR_TO_DATE() method for this. Let us first create a table −mysql> create table DemoTable -> ( -> DueDatetime varchar(100) -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('22-06-2019 14:40'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('02-07-2015 13:10'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------------------+ | DueDatetime | +------------------+ | 22-06-2019 14:40 | | 02-07-2015 13:10 | ... Read More

Is there a way to retrieve the minimum value of fields in MySQL?

Kumar Varma
Updated on 30-Jun-2020 12:32:19

119 Views

Yes, you can use LEAST() function from MySQL −select least(yourColumnName1, yourColumnName2, ...N) from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Date1 date,    -> Date2 date,    -> Date3 date    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-03-31', '2019-01-01', '2019-03-05'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------------+------------+------------+ | Date1      | Date2 | ... Read More

Create a table named “select” in SQL databases?

Sharon Christine
Updated on 30-Jun-2020 12:32:59

162 Views

Since “select” is a reserved word in MySQL, we cannot create a table name with it. But, if you still want to create such a table, surround the word select with quote.Let us first create a table −mysql> create table `select` -> ( -> Number int -> ); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into `select` values(10); Query OK, 1 row affected (0.16 sec) mysql> insert into `select` values(20); Query OK, 1 row affected (0.11 sec) mysql> insert into `select` values(30); Query OK, 1 row affected (0.12 ... Read More

Store a variable with the result of a MySQL SELECT CASE?

Sharon Christine
Updated on 30-Jun-2020 12:34:14

1K+ Views

For this, use SELECT CASE. Let us first create a table −mysql> create table DemoTable    -> (    -> Num1 int,    -> Num2 int    -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 30); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------+------+ | Num1 | Num2 | +------+------+ |   10 |   30 | +------+------+ 1 row in set (0.00 sec)Following is the query to store ... Read More

Can we use “IF NOT IN” in a MySQL procedure?

Kumar Varma
Updated on 30-Jun-2020 12:15:04

165 Views

Let us first see the syntax of IF NOT IN in MySQL −if(yourVariableName  NOT IN (yourValue1, yourValue2, ........N) ) then    statement1 else    statement2 endif    Let us implement the above syntax to use IF NOT IN −mysql> DELIMITER // mysql> CREATE PROCEDURE IF_NOT_INDemo(IN value int)    ->    BEGIN    ->       if(value NOT IN  (10, 20, 30) ) then    ->          select "Value Not Found";    ->       else    ->          select "Value Found";    ->       end if;    ->    END ... Read More

Count rows having three or more rows with a certain value in a MySQL table

Rama Giri
Updated on 30-Jul-2019 22:30:26

132 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> UserId int    -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.09 sec) ... Read More

Select last record and update it in MySQL?

Kumar Varma
Updated on 30-Jul-2019 22:30:26

3K+ Views

For this, you can use ORDER BY DESC LIMIT. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.34 sec)Display all records from the table using select statement −mysql> ... Read More

AUTO_INCREMENT in MySQL can be signed by default?

Rama Giri
Updated on 30-Jul-2019 22:30:26

337 Views

Yes, the AUTO_INCREMENT in MySQL will be signed (Positive and Negative Value both) by default.Let us first create a table −mysql> create table DemoTable    -> (    -> MyNumber int AUTO_INCREMENT PRIMARY KEY    -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command. Here, we have set negative values as well for AUTO_INCREMENT column −mysql> insert into DemoTable values() ; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(-100); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(-300); Query OK, 1 row affected ... Read More

How to order an alphanumeric column in MySQL?

Sharon Christine
Updated on 30-Jun-2020 12:16:32

1K+ Views

To order an alphanumeric column with values like “100X, “2Z”, etc. use the ORDER BY. Let us first create a table −mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2X'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('100Y'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('100X'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2Z'); Query OK, 1 row affected (0.14 sec) mysql> ... Read More

Multiply values of two columns and display it a new column in MySQL?

Kumar Varma
Updated on 30-Jul-2019 22:30:26

3K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> NumberOfItems int,    -> Amount int    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(4, 902); Query OK, 1 row affected (0.45 sec) mysql> insert into DemoTable values(5, 1000); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(3, 80); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+---------------+--------+ | NumberOfItems | Amount | +---------------+--------+ |   ... Read More

Advertisements