AmitDiwan has Published 10744 Articles

How to display the day name on the basis of Date of Birth records in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:52:22

1K+ Views

Use the DAYNAME() to display the day name from records with Date of Birth.Let us first create a table −mysql> create table DemoTable795 ( DateOfBirth date ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable795 values('1996-01-21'); ... Read More

Get number of fields in MySQL table?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:49:46

221 Views

To display number of fields in MySQL, use the COUNT(*). Following is the syntax −select COUNT(*) AS anyAliasName from INFORMATION_SCHEMA.COLUMNS where table_name = yourTableName AND TABLE_SCHEMA = yourDatabaseName;Let us first create a table −mysql> create table DemoTable794 ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ... Read More

Write a single MySQL query to exclude a record and display NULL value

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:47:49

2K+ Views

To check records which are NULL, use IS NULL. However, to exclude any of the records, use the NOT IN clause. Use both of them in the same query.Let us first create a table −mysql> create table DemoTable793 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ... Read More

Reshuffle the values in a table with MySQL

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:44:50

143 Views

To reshuffle the values in a table, use MySQL RAND().Let us first create a table −mysql> create table DemoTable792 ( Name varchar(100), Subject varchar(100) ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable792 ... Read More

MySQL query to exclude some of the values from the table

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:43:11

2K+ Views

Use NOT IN() to exclude some of the values from the table.Let us first create a table −mysql> create table DemoTable791 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100) ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table ... Read More

Get the highest score value from a single column and the greatest from two columns in MySQL

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:41:28

183 Views

Let us first create a table −mysql> create table DemoTable790 ( Score1 int, Score2 int ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command −mysql> insert into DemoTable790 values(98, 76); Query OK, 1 row affected (0.12 sec) ... Read More

Display records where first and last name begins with the same letter in MySQL

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:38:59

831 Views

To check for the 1st letter of the first and last name, you need to use the LEFT().Let us first create a table −mysql> create table DemoTable789 ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (0.78 sec)Insert some records in the ... Read More

Sort data for duplicate record in MySQL

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:37:00

500 Views

Use ORDER BY to sort data for duplicate record.Let us first create a table −mysql> create table DemoTable788 ( FirstName varchar(100), Score int ); Query OK, 0 rows affected (1.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable788 values('Chris', ... Read More

Select a specific value between two column values in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:35:21

2K+ Views

Let us first create a table −mysql> create table DemoTable787 ( Score1 int, Score2 int, Name varchar(100) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable787 values(34, 56, 'Chris'); Query ... Read More

How to display column values as CSV in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2019 08:33:31

670 Views

To display column values as CSV, use GROUP_CONCAT().Let us first create a table −mysql> create table DemoTable786 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100) )   AUTO_INCREMENT=101; Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Advertisements