AmitDiwan has Published 10740 Articles

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

AmitDiwan

AmitDiwan

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

214 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

191 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

565 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

354 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

235 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

240 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

388 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

777 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

How to change MySQL ending statement?

AmitDiwan

AmitDiwan

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

219 Views

To change the MySQL ending statement, you can use DELIMITER −DELIMITER anySymbolAbove, anySymbol is the symbol you can set. The default is DELIMITER ;Let us first create a table −mysql> DELIMITER // mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> )// ... Read More

Advertisements