AmitDiwan has Published 10744 Articles

MySQL Order by a specific column x and display remaining values in ascending order

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 07:19:59

151 Views

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

Delete a specific record from a MySQL table by using AND in WHERE clause

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 07:08:22

186 Views

MySQL AND is used in WHERE to fetch a record by filtering using multiple conditions. Let us first create a table−mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table ... Read More

Sort records with special characters like '2321/78/54-6'

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 06:01:18

172 Views

To sort, use ORDER BY SUBSTRING(). Let us first create a table −mysql> create table DemoTable    -> (    -> Value varchar(40)    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2321/78/54-6')    -> ; Query ... Read More

Order VARCHAR records with string and numbers in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:52:01

540 Views

For this, use ORDER BY clause. Let us first create a table −mysql> create table DemoTable    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('101J'); Query OK, 1 row ... Read More

Get number of users of different type in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:46:26

328 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> UserName varchar(20),    -> UserType ENUM('New User', 'Registered User')    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'New User'); Query ... Read More

Round records with numbers in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:41:20

214 Views

To round number, use MySQL ROUND(). Let us first create a table −mysql> create table DemoTable    -> (    -> Amount DECIMAL(10, 4)    -> ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100.578); Query OK, 1 ... Read More

Display record with most recent time in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:40:31

196 Views

You can use ORDER BY STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable    -> (    -> DueTime varchar(20)    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('7:30AM'); Query OK, 1 row ... Read More

MySQL syntax error (in SELECT query) while using ‘group’ as table name

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:39:11

1K+ Views

The group is a reserved keyword, you can’t use it as table name. Therefore, on using it as table name would lead to an error. To avoid such error, you need to use enclosed backticks symbol around the table name ‘group’.Let us now see an example and create a table ... Read More

Set conditions while adding column values in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:38:16

337 Views

To set conditions while adding column values, use MySQL IF(). Let us first create a table −mysql> create table DemoTable    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table ... Read More

Set conditions for columns with values 0 or 1 in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:36:57

741 Views

To set conditions, use CASE WHEN statement in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int,    -> Value4 int    -> ); Query OK, 0 rows affected (0.98 sec)Insert some records ... Read More

Advertisements