AmitDiwan has Published 10740 Articles

Using ! operator in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:45:17

137 Views

For same results, do not use ! operator. The NOT keyword is already provided by MySQL. Let us first create a table −mysql> create table DemoTable1560    -> (    -> Value1 int    -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert ... Read More

How to order results of a query randomly & select random rows in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:44:02

485 Views

To order results of a query randomly, use ORDER BY RAND(). The syntax is as follows −select * from DemoTable1559 where yourColumnName IN(yourValue1, yourValue2, ....N) order by rand() limit yourLimitValue;Let us first create a table −mysql> create table DemoTable1559    -> (    -> EmployeeId int,    -> EmployeeName varchar(20), ... Read More

Display USD currency records with the correct format in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:43:16

486 Views

Use FORMAT() in MySQL to display USD currency records in the correct form. Let us first create a table −mysql> create table DemoTable    -> (    -> Amount DECIMAL(15, 4)    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> ... Read More

Shuffling column values with MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:39:46

956 Views

To shuffle elements, you need to use ORDER BY RAND(). Let us first create a table −mysql> create table DemoTable1557    -> (    -> SubjectId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> SubjectName varchar(20)    -> ); Query OK, 0 rows affected (0.91 sec)Insert some records in the ... Read More

Update MySQL table on INSERT command with triggers?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:37:22

283 Views

Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.52 sec)Here is the query to create second table −mysql> create table DemoTable2    -> (    -> EmployeeId int,   ... Read More

Quickly search for a string in MySQL database?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:31:11

527 Views

Use FULLTEXT search to quickly search for a string. Let us first create a table −mysql> create table DemoTable1554    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.63 sec)Here is the query to create full text search −mysql> create fulltext index faster_title on ... Read More

Display an error while inserting duplicate records in a MySQL table

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:29:34

416 Views

For this, you can use UNIQUE KEY. Let us first create a table −mysql> create table DemoTable1553    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeSalary int    -> ); Query OK, 0 rows affected (0.47 sec)Here is the query ... Read More

Why does the update command in MySQL insist on using slanted single quotes?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:27:54

114 Views

Use single quotes on string input value. If there is an identifier like table name or column name, then do not use single quotes (use backticks).Let us first create a table −mysql> create table DemoTable1552    -> (    -> `key` int,    -> Name varchar(20)    -> ); Query ... Read More

How to select only 3 ordered rows on a MySQL table?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:26:23

510 Views

For this, you can use ORDER BY clause along with LIMIT. Let us first create a table −mysql> create table DemoTable1551    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20)    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in ... Read More

Searching from a comma separated MySQL column?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:25:26

295 Views

To search from a comma-separated column, use the FIND_IN_SET() method. Let us first create a table −mysql> create table DemoTable    -> (    -> Value varchar(20)    -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('41, ... Read More

Advertisements