AmitDiwan has Published 10740 Articles

Get three records having higher value from MySQL

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:15:23

116 Views

Let us first create a table −mysql> create table DemoTable1614    -> (    -> StudentName varchar(20),    -> StudentScore int    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1614 values('Adam', 65); Query OK, 1 row affected ... Read More

Is there a function similar to Oracle's trunc (sysdate) in MySQL?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:13:01

893 Views

Yes, you can use DATE() to get only date part in MySQL and you can use CURDATE() to get the current date in MySQL.The current date is as follows −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-10-20 | +------------+ 1 row in set (0.00 sec)Let us first create ... Read More

Get the size of selected rows in MySQL

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:09:47

2K+ Views

To get the size of selected rows, use CHAR_LENGTH(). Let us first create a table −mysql> create table DemoTable1612    -> (    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Combine multiple text records to one in MySQL

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:04:48

286 Views

To combine multiple text records, use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable1611    -> (    -> Value text    -> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1611 values('John'); Query OK, 1 ... Read More

Custom sorting using two different columns in MySQL?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:01:17

245 Views

For this, use ORDER BY clause along with CASE statement. Let us first create a table −mysql> create table DemoTable1610    -> (    -> Marks int,    -> Name varchar(20)    -> ) ; Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command ... Read More

How to correctly use DELIMITER in a MySQL stored procedure?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 05:59:31

361 Views

The correct way is as follows −DELIMITER // CREATE PROCEDURE yourStoredProcedureName() BEGIN  IF  yourCondition then      yourStatement1 ; else     yourStatement2 ; END IF ; END // DELIMITER ;Let us now see an example and create a stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE delimiter_demo() ... Read More

Select the minimum value from the maximum values of two tables with a single MySQLquery?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 05:58:03

203 Views

For this, you can use UNION in MySQL. Let us first create a table −mysql> create table DemoTable1    -> (    -> Value int    -> )    -> ; Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 ... Read More

What are the minimum MySQL user privileges to allow optimize and repair?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 05:51:08

431 Views

The select and insert statements are the minimum required MySQL user privileges to allow optimize and repair.You can use below syntax to give insert and select privileges to the user −grant insert, select on yourDatabaseName.* to 'yourUserName'@'localhost';At first, here is the query to create a user −mysql> create user 'Emma'@'localhost' ... Read More

Query for implementing MySQL LIKE as MySQL IN?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 05:41:49

220 Views

To implement a query like MySQL IN(), you need to use COUNT(), IF() along with LIKE operator. Let us first create a table −mysql> create table DemoTable    -> (    -> Subject varchar(80)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using ... Read More

Fetch maximum value from multiple columns with null and non-null values?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 05:39:49

481 Views

For this, you can use COALESCE(). For the maximum value, use GREATEST() in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.61 sec)Insert some ... Read More

Advertisements