AmitDiwan has Published 10744 Articles

How to display coming Sunday's date for all the date records in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:13:44

250 Views

Let us first create a table −mysql> create table DemoTable(GetSundayDate date); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-08-07'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2018-09-05'); Query OK, 1 row affected (0.22 sec) ... Read More

Convert varchar to unsigned integer in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:11:43

779 Views

To convert varchar to unsigned integer, use CAST() function. Let us first create a table −mysql> create table DemoTable868(Amount varchar(100)); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable868 values('781'); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More

How to get the top 3 salaries from a MySQL table with record of Employee Salaries?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:09:05

1K+ Views

For this, use LIMIT and OFFSET. Let us first create a table −mysql> create table DemoTable867(EmployeeSalary int); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable867 values(63737); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable867 values(899833); Query ... Read More

Perform SUM and SUBTRACTION on the basis of a condition in a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:05:37

2K+ Views

For this, use CASE statement and set for both SUM and SUBTRACTION. Let us first create a table −mysql> create table DemoTable866(    Status varchar(100),    Amount int ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable866 values('ACTIVE', 50); ... Read More

What does parenthesis mean in MySQL SELECT (COLNAME)?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:02:08

435 Views

The SELECT(COLNAME) means, we are creating an alias for that column. Let us see an example and create a table −mysql> create table DemoTable865(    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable865 ... Read More

Return only the non-empty and non-null values from a table and fill the empty and NULL values with the corresponding column values in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:01:17

224 Views

Let us first create a table −mysql> create table DemoTable839(    StudentFirstName varchar(100),    StudentLastName varchar(100) ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable839 values('Chris', 'Brown'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable839 values('', ... Read More

How can I create a MySQL table with a column with only 3 possible given values?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:59:00

269 Views

For this, use the ENUM data type. Let us first create a table −mysql> create table DemoTable838(Color ENUM('RED', 'GREEN', 'BLUE')); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable838 values('RED'); Query OK, 1 row affected (0.11 sec) mysql> insert into ... Read More

How to compare Year, Month and Day in a MySQL query and display matching records

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:58:07

508 Views

For this, you can use DATE(). Let us first create a table −mysql> create table DemoTable864(DueDateTime timestamp); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable864 values('2019-01-10 12 −34 −55'); Query OK, 1 row affected (0.26 sec) mysql> insert into ... Read More

Replace the empty values from a MySQL table with a specific value

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:57:02

432 Views

Let us first create a table −mysql> create table DemoTable837(Name varchar(100)); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable837 values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable837 values(''); Query OK, 1 row affected (0.23 sec) ... Read More

MySQL query to get the dates between range of records displaying student’s Date of Birth?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:55:31

373 Views

For fetching records between dates, use BETWEEN. Let us first create a table −mysql> create table DemoTable863(StudentDateOfBirth date); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable863 values('1998-01-10'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable863 values('2000-10-15'); ... Read More

Advertisements