Found 4378 Articles for MySQL

Get day name for the corresponding date in MySQL?

AmitDiwan
Updated on 31-Dec-2019 06:59:51

79 Views

To fetch day name, use DAYNAME() function in MySQL. Let us first create a table −mysql> create table DemoTable1954    (    ShippingDate date    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1954 values('2019-12-15'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1954 values('2018-04-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1954 values('2019-01-31'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1954 values('2016-10-01'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * ... Read More

Display custom text in a new column on the basis of null values in MySQL?

AmitDiwan
Updated on 31-Dec-2019 06:57:30

475 Views

Let us first create a table −mysql> create table DemoTable1953    (    StudentName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1953 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1953 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1953 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1953 values(NULL); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1953;This will produce the following output −+-------------+ | ... Read More

Set custom messages on the basis of a column with student marks in MySQL

AmitDiwan
Updated on 31-Dec-2019 06:53:59

88 Views

For this, use CASE statement. Let us first create a table −mysql> create table DemoTable1952    (    Marks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1952 values(35); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(65); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(55); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(39); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1952;This will produce ... Read More

Split float value in two columns of a MySQL table?

AmitDiwan
Updated on 31-Dec-2019 06:50:55

617 Views

To split float value in two columns, the first column will have a value before decimal. The second column will have a value after decimal. For this, you can use SUBSTRING_INDEX() along with CAST(). Let us first create a table −mysql> create table DemoTable1951    (    Value1 varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1951 values('100.50'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1951 values('70.90'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1951 values('1000.55'); Query OK, 1 row affected ... Read More

Combine SUM and FORMAT in MySQL to format the result

AmitDiwan
Updated on 31-Dec-2019 06:48:29

2K+ Views

Let us create a table −mysql> create table DemoTable1950    (    Amount float    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1950 values(45.60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(101.78); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(75.90); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(89.45); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1950;This will produce the following output −+--------+ | Amount ... Read More

Set NOT NULL attribute to an existing column in MySQL

AmitDiwan
Updated on 31-Dec-2019 06:47:21

209 Views

To set NOT NULL attribute to an existing column, use ALTER TABLE command. Let us first create a table −mysql> create table DemoTable1949    (    UserId int,    UserName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Here is the query to set NOT NULL attribute to an existing column −mysql> alter table DemoTable1949 modify UserName varchar(20) not null; Query OK, 0 rows affected (0.00 sec) Records: 0  Duplicates: 0  Warnings: 0Let us check the description of table −mysql> desc DemoTable1949;This will produce the following output −+----------+-------------+------+-----+---------+-------+ | Field    | Type        | Null | ... Read More

Sort only numbers from alphanumeric string in MySQL?

AmitDiwan
Updated on 31-Dec-2019 06:45:01

239 Views

To sort only numbers from alphanumeric string, use ORDER BY RIGHT(). Let us first create a table −mysql> create table DemoTable1948    (    StudentCode varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1948 values('121John_567'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1948 values('Adam_101'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1948 values('Bob_563'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1948 values('Sam_346'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> ... Read More

MySQL SELECT from a subquery and then perform DELETE?

AmitDiwan
Updated on 31-Dec-2019 06:41:19

1K+ Views

Let us first create a table −mysql> create table DemoTable1947    (    Id int,    Name varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1947 values(101, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(102, 'David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(103, 'Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(104, 'Bob'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(105, 'Sam'); Query OK, 1 row affected (0.00 sec)Display ... Read More

Fetch the count of a specific date in a MySQL table

AmitDiwan
Updated on 31-Dec-2019 06:37:27

437 Views

Let us first create a table −mysql> create table DemoTable1946    (    ShippingDate date    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2018-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2017-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-04-22'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2015-12-11'); Query OK, 1 ... Read More

Insert records from multiple tables in MySQL

AmitDiwan
Updated on 31-Dec-2019 06:31:50

5K+ Views

To insert records from multiple tables, use INSERT INTO SELECT statement. Here, we will insert records from 2 tables.Let us first create a table −mysql> create table DemoTable1943    (    Name varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1943 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1943 values('Robert'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1943;This will produce the following output −+--------+ | Name   | +--------+ | Chris ... Read More

Advertisements