Found 4378 Articles for MySQL

Fetch ordered records after a specific limit in MySQL

AmitDiwan
Updated on 23-Aug-2019 06:29:34

75 Views

For this, you can use a subquery. Let us first create a table −mysql> create table DemoTable618 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(100) ); Query OK, 0 rows affected (1.45 sec)Insert some records in the table using insert command −mysql> insert into DemoTable618(StudentFirstName) values('David'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable618(StudentFirstName) values('Chris'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable618(StudentFirstName) values('Robert'); Query OK, 1 row affected (0.54 sec) mysql> insert into DemoTable618(StudentFirstName) values('Sam'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable618(StudentFirstName) values('Mike'); Query OK, 1 ... Read More

Select the next row after skipping every 2 rows in MySQL

AmitDiwan
Updated on 23-Aug-2019 06:21:05

367 Views

To skip rows, you can use OFFSET. Let us first create a table −mysql> create table DemoTable617(Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100)); Query OK, 0 rows affected (1.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable617(FirstName) values('John'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable617(FirstName) values('Sam'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable617(FirstName) values('Carol'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable617(FirstName) values('Mike'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable617(FirstName) values('David'); Query OK, 1 row affected (0.17 sec) ... Read More

How to add columns values with suffixed currency sign in MySQL

AmitDiwan
Updated on 23-Aug-2019 06:15:11

165 Views

For this, you can use aggregate function SUM(). Let us first create a table:mysql> create table DemoTable616 (Price varchar(100)); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable616 values('€200.00'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable616 values('€300.00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable616 values('€500.00'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable616;This will produce the following output −+-----------+ | Price     | +-----------+ | €200.00 | | ... Read More

Delete a specific record on the basis of EmployeeId in MySQL

AmitDiwan
Updated on 22-Aug-2019 14:11:16

253 Views

Let us first create a table −mysql> create table DemoTable615 (EmployeeId varchar(100), EmployeeName varchar(100)); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable615 values('EMP-101', 'Adam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable615 values('EMP-1001', 'David'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable615 values('EMP-1002', 'Chris'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable615 values('EMP-1003', 'Robert'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable615;This will produce the following output −+------------+--------------+ | ... Read More

Return similar names from different columns with distinct space allocations in MySQL?

AmitDiwan
Updated on 22-Aug-2019 13:57:26

64 Views

For this, use LTRIM() and RTRIM(), since the names are similar but have different left and right space allocations. For example, “ John “ and “John”.Let us first create a table −mysql> create table DemoTable614 (EnterName varchar(100), ReennterName varchar(100)); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command −mysql> insert into DemoTable614 values(' John ', 'John'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable614 values('Carol ', 'Bob'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable614 values('David ', 'David'); Query OK, 1 row affected (0.23 sec)Display all records from ... Read More

Perform MySQL update with AND operator

AmitDiwan
Updated on 22-Aug-2019 13:53:51

82 Views

Let us first create a table −mysql> create table DemoTable613 (Id int, Age int, isMarried tinyint(1)); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable613 values(100, 29, 0); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable613 values(200, 22, 0); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable613 values(300, 30, 1); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable613;This will produce the following output −+------+------+-----------+ | Id   | Age  | isMarried | +------+------+-----------+ ... Read More

How to create conditions in a MySQL table with multiple columns?

AmitDiwan
Updated on 22-Aug-2019 13:48:29

282 Views

For conditions, use IF(). Following is the syntax −IF(yourCondition, trueStatement, falseStatement);Let us first create a table −mysql> create table DemoTable612 (Number1 int, Number2 int, Score int); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable612 values(10, 20, 1000); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable612 values(30, 40, 500); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable612 values(50, 70, 1200); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable612 values(100, 120, 400); Query OK, 1 row affected (0.16 sec)Display all records from ... Read More

Querying age from DOB in MySQL?

AmitDiwan
Updated on 22-Aug-2019 13:15:13

251 Views

Let us first create a table −mysql> create table DemoTable611 (DOB date); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable611 values('1996-04-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable611 values('2001-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable611 values('2004-12-21'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable611 values('2000-02-03'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable611;This will produce the following output −+------------+ | DOB       | ... Read More

Selecting the top occurring entries in MySQL from a table with duplicate values?

AmitDiwan
Updated on 22-Aug-2019 13:13:01

73 Views

Let us first create a table −mysql> create table DemoTable610 (SubjectName varchar(100)); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable610 values('Java'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable610 values('MongoDB'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable610 values('MySQL'); Query OK, 1 row affected (0.08 sec) mysql> ... Read More

MySQL query to remove first digit?

AmitDiwan
Updated on 22-Aug-2019 13:05:05

612 Views

For this, use SUBSTR(). Following is the syntax −update yourTableName set yourColumnName=substr(yourColumnName, 2);Let us first create a table −mysql> create table DemoTable607 (Value varchar(100)); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable607 values('83967364'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable607 values('10939432'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable607 values('932111'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable607;This will produce the following output −+----------+ | Value    | +----------+ | 83967364 ... Read More

Advertisements