Shuffling Column Values with MySQL

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

953 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 table using insert command −mysql> insert into DemoTable1557(SubjectName) values('MySQL'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('MongoDB'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('Java'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('C'); Query OK, 1 row affected ... Read More

Update MySQL Table on Insert Command with Triggers

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

271 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,    -> EmployeeName varchar(20)    -> ); Query OK, 0 rows affected (0.51 sec)Let us now create a trigger to update MySQL table on insert command −mysql>  DELIMITER // mysql>     CREATE TRIGGER updateDemoOnInsert    ->      AFTER INSERT ON DemoTable2    ->         FOR EACH ... Read More

Quickly Search for a String in MySQL Database

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

519 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 DemoTable1554(Title); Query OK, 0 rows affected, 1 warning (7.09 sec) Records: 0  Duplicates: 0  Warnings: 1Insert some records in the table using insert command −mysql> insert into DemoTable1554 values('John is working on MySQL database'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable1554 values('Adam Smith is working on ... Read More

Display Error While Inserting Duplicate Records in MySQL Table

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

411 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 to add unique key −mysql> alter table DemoTable1553 add unique(EmployeeSalary); Query OK, 0 rows affected (0.53 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1553(EmployeeName, EmployeeSalary) values('Chris', 45000); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1553(EmployeeName, EmployeeSalary) ... Read More

Why Does the UPDATE Command in MySQL Use Slanted Single Quotes?

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

111 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 OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1552 values(101, 'Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1552 values(102, 'David'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1552 values(103, 'Mike'); Query OK, 1 row ... Read More

Select Only 3 Ordered Rows on a MySQL Table

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

504 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 the table using insert command −mysql> insert into DemoTable1551(EmployeeName) values('Chris'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1551(EmployeeName) values('Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1551(EmployeeName) values('Mike'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1551(EmployeeName) values('Sam'); Query OK, 1 row ... Read More

Searching from a Comma Separated MySQL Column

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

291 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, 14, 94'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('64, 84, 94'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('44, 74, 103, 104'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('904, 1004, 1444, 1544'); Query OK, 1 row ... Read More

Maintain Custom Order of IDs Passed in MySQL

AmitDiwan
Updated on 12-Dec-2019 06:23:51

254 Views

To maintain the custom order of IDs, use ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable1550    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1550 values(101, 'Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1550 values(110, 'Bob'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable1550 values(105, 'Carol'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1550 values(109, 'Mike'); Query OK, 1 row ... Read More

Detect Encoding and Mixed Line Endings in SAP

seetha
Updated on 12-Dec-2019 06:23:03

331 Views

You can make use of CL_ABAP_FILE_UTILITIES => CHECK_FOR_BOM to define file encoding type and use constantly of class CL_ABAP_CHAR_UTILITIES to process the files.ClassCL_ABAP_CHAR_UTILITIESShort DescriptionUtilities for Processing Characters

Insert Date Record to the Same Table with Different Date Formats in MySQL

AmitDiwan
Updated on 12-Dec-2019 06:22:41

431 Views

For this, you can use the INSERT INTO SELECT statement. To format the date, use the DATE_FORMAT() function. Let us first create a table −mysql> create table DemoTable    -> (    -> DateOfJoining datetime,    -> JoiningDate text    -> ); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(DateOfJoining) values('2019-10-26 13:52:10'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(DateOfJoining) values('2018-12-31 15:20:40'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement−mysql> select *from DemoTable;This will produce the following output −+---------------------+-------------+ ... Read More

Advertisements