Found 4378 Articles for MySQL

How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”

AmitDiwan
Updated on 07-Oct-2019 11:47:15

154 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(40) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Ethan'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Johnson'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected ... Read More

Get left part of the string on the basis of last occurrence of delimiter in MySQL?

AmitDiwan
Updated on 07-Oct-2019 11:42:27

77 Views

For this, use LEFT() method. For manipulation, we have used the LOCATE() and the REVERSE() method.Let us first create a table −mysql> create table DemoTable (    Title text ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('$/This$is[MySQL]$/MySQL[FirstClass]$MySQL[SecondClass]'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('$/This$is[Java]$/Java[FirstClass]$Java[SecondClass]'); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------------------------------------------------------+ | Title                       ... Read More

MySQL string manipulation to count only sub-part of duplicate values in IP ADDRESS records?

AmitDiwan
Updated on 07-Oct-2019 11:40:02

92 Views

For such string manipulations, you need to use MySQL SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable (    SystemIpAddress text ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('192.168.130.67'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('192.168.130.87'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('192.168.131.47'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('192.168.134.50'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('192.168.131.12'); Query OK, 1 row affected (0.21 sec)Display ... Read More

Is there a need to insert auto_increment column values in MySQL while using INSERT statement?

AmitDiwan
Updated on 07-Oct-2019 11:34:56

97 Views

No, there’s no need to insert auto_increment column values, since it begins from 1 and inserts on its own. This is because we have set it as auto increment. Let us first create a table −mysql> create table DemoTable (    EmployeeId int NOT NULL AUTO_INCREMENT,    EmployeeName varchar(30),    EmployeeSalary int,    PRIMARY KEY(EmployeeId) ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName, EmployeeSalary) values('Chris', 56789); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(EmployeeName, EmployeeSalary) values('David', 78909); Query OK, 1 row affected (0.14 sec) mysql> ... Read More

MySQL query to replace a column value

AmitDiwan
Updated on 07-Oct-2019 11:30:23

317 Views

Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Score int ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score) values(56); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(Score) values(78); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Score) values(34); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Score) values(55); Query OK, 1 row affected (0.37 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce ... Read More

MySQL query to fetch records where decimal is a whole number

AmitDiwan
Updated on 07-Oct-2019 11:24:49

337 Views

For this, use FLOOR() function. Here, we will be fetching records like 12.00, 35.00, etc. from a list with records like 5.23, 8.76, 12.00, 22.68, etc. Let us first create a table −mysql> create table DemoTable (    Value DECIMAL(4, 2) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(54.20); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(55.0); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(7.8); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(9.0); Query OK, ... Read More

Find the percentage of a student on basis of marks and add percent sign (%) to the result in SQL

AmitDiwan
Updated on 07-Oct-2019 11:23:05

1K+ Views

Let us first create a table −mysql> create table DemoTable (    Marks int ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(65); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(45); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.33 sec)Display all records from the table using select statement −mysql> select ... Read More

MySQL query to delete a row if two columns are equal

AmitDiwan
Updated on 07-Oct-2019 11:20:38

388 Views

Use DELETE for this. Let us first create a table −mysql> create table DemoTable (    Name varchar(40),    Score1 int ,    Score2 int ); Query OK, 0 rows affected (2.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 56, 76); Query OK, 1 row affected (0.66 sec) mysql> insert into DemoTable values('Chris', 77, 77); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('David', 89, 98); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More

How to get the difference between date records and the current date in MySQL?

AmitDiwan
Updated on 07-Oct-2019 11:16:46

148 Views

Let’s say the current date is 2019-09-06. For our example, we will first create a table −mysql> create table DemoTable (    AdmissionDate date ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-08'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2018-09-06'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2016-10-26'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------+ | AdmissionDate | +---------------+ | 2019-01-08 ... Read More

Update a column of text with MySQL REPLACE()

AmitDiwan
Updated on 07-Oct-2019 10:52:50

693 Views

Let us first create a table −mysql> create table DemoTable (    Code varchar(100) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('8565-9848-7474'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('9994-6464-8737'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('6574-9090-7643'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------------+ | Code          | +----------------+ | 8565-9848-7474 | | 9994-6464-8737 | | ... Read More

Advertisements