Found 4378 Articles for MySQL

MySQL number-string formatting to pad zeros on the left of a string with numbers after a slash

AmitDiwan
Updated on 08-Nov-2019 11:20:41

206 Views

Let us first create a table −mysql> create table DemoTable1369     -> (     -> BatchId varchar(20)     -> ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command. We have inserted numbers here separated by a slash −mysql> insert into DemoTable1369 values('19/5'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1369 values('19/78'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1369 values('19/567'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1369 values('19/1234'); Query OK, 1 row affected (0.11 sec)Display all records from the table ... Read More

Implement numbering in MySQL GROUP_CONCAT

AmitDiwan
Updated on 08-Jul-2020 11:58:17

377 Views

Let us first create a table −mysql> create table DemoTable1627     -> (     -> FirstName varchar(20),     -> LastName varchar(20)     -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1627 values('John', 'Smith'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1627 values('John', 'Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1627 values('Adam', 'Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1627 values('Carol', 'Taylor'); Query OK, 1 row affected (0.08 sec)Display all records from the table using ... Read More

MySQL query to append a number of stars based on string length?

AmitDiwan
Updated on 08-Nov-2019 11:17:51

157 Views

For this, you can use RPAD(). Let us first create a table −mysql> create table DemoTable1626     -> (     -> Name varchar(20)     -> ); Query OK, 0 rows affected (0.37 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1626 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1626 values('Bob'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1626 values('Robert'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable1626; This will produce the following output −+--------+ ... Read More

Adding dash between spaces in field name in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:16:51

349 Views

You can use REPLACE() for this. Let us first create a table −mysql> create table DemoTable1625     -> (     -> FullName varchar(20)     -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1625 values('John Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1625 values('Adam Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1625 values('John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1625 values('Carol Taylor'); Query OK, 1 row affected (0.14 sec)Display all records from the ... Read More

SELECT * WHERE var == [one of many alternatives] in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:15:50

175 Views

Use IN() for select * where var== [one of many alternatives]. Let us first create a table −mysql> create table DemoTable1624     -> (     -> ClientId int,     -> ClientName varchar(20)     -> ); Query OK, 0 rows affected (0.39 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1624 values(101, 'Chris Brown'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1624 values(102, 'David Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1624 values(103, 'John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1624 ... Read More

How to sort an alphanumeric column with different lengths in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:14:54

119 Views

Let us first create a table −mysql> create table DemoTable1623     -> (     -> StudentCode varchar(20)     -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1623 values('STU-MIT-143'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1623 values('STU-MIT-10'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1623 values('STU-MIT-150'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1623 values('STU-MIT-148'); Query OK, 1 row affected (0.22 sec)Display all records from the table using select statement −mysql> select * from DemoTable1623; This ... Read More

How to search for the exact string value in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:10:21

127 Views

To search for the exact string value, use the concept of COLLATE. Let us first create a table −mysql> create table DemoTable1620     -> (     -> Subject varchar(20)     -> ); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1620 values('mysql'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1620 values('MySql'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1620 values('mYSQL'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1620 values('MySQL'); Query OK, 1 row affected (0.26 sec) mysql> insert ... Read More

Convert datetime to get month name in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:09:24

275 Views

To get only month name, the syntax is as follows −select date_format(yourColumnName, '%M %Y') from yourTableName;Let us first create a table −mysql> create table DemoTable1619     -> (     -> ArrivalTime datetime     -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1619 values(now()); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable1619 values(curdate()); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1619 values('2019-12-31'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select * ... Read More

How can I enhance my select query to make it faster in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:08:21

98 Views

For quicker querying, use MySQL IN() because it uses indexing internally. Let us first create a table −mysql> create table DemoTable1618     -> (     -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,     -> ClientName varchar(20),     -> ClientEmailId varchar(30)     -> ); Query OK, 0 rows affected (1.53 sec)Insert some records in the table using insert command:mysql> insert into DemoTable1618(ClientName, ClientEmailId) values('Chris Brown', 'Brown323@gmail.com'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1618(ClientName, ClientEmailId) values('David Miller', 'MillerDavid@gmail.com'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1618(ClientName, ClientEmailId) values('John Doe', ... Read More

Create a Stored Procedure with MySQL and set a limit to display only a specific number of records

AmitDiwan
Updated on 08-Nov-2019 11:06:45

595 Views

Let us first create a table −mysql> create table DemoTable1368     -> (     -> ClientId int,     -> ClientName varchar(20)     -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1368 values(101, 'Adam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1368 values(102, 'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1368 values(103, 'John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1368 values(104, 'Sam'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1368 values(105, ... Read More

Advertisements