Found 4218 Articles for MySQLi

How can we sort a query using ORDER BY CASE WHEN REGEXP?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

605 Views

Use regular expression along with CASE statement. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value varchar(20)    ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('101'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Value) values('P'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Value) values('A'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Value) values('53'); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

How select specific rows in MySQL?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

648 Views

To select specific rows, use FIND_IN_SET() function in MySQL. Let us first create a table −mysql> create table DemoTable    (    ListOfValues varchar(200)    ); Query OK, 0 rows affected (0.31 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('112, 114, 567, Java, 345'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable values('222, 214, 256'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable values('2, 567, 98, C'); Query OK, 1 row affected (0.06 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This ... Read More

MySQL filtering by multiple columns?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

2K+ Views

To perform filtering by multiple columns, use where clause along with OR. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(10),    Score int    ); Query OK, 0 rows affected (0.28 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Score) values('John', 80); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(Name, Score) values('John', 90); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Name, Score) values('Carol', 89); Query OK, 1 row affected (0.04 sec) ... Read More

Fetch data between two rows in MySQL?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

450 Views

To fetch data between two rows, use the concept of LIMIT. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(10)    ); Query OK, 0 rows affected (0.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Larry'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected ... Read More

How can I avoid “repair with keycache” in MySQL?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

320 Views

To avoid repair with keycache in MySQL, you need to follow the below syntax −create table yourNewTableName as (select *from yourOldTableName); alter table yourNewTableName add index(yourCoumnName);Let us first create a table −mysql> create table DemoTable    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentFirstName varchar(20),    StudentLastName varchar(20)    ); Query OK, 0 rows affected (0.24 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('John', 'Doe'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('David', 'Miller'); Query OK, 1 row affected (0.05 sec)Display all records from ... Read More

How can I calculate the total value of products from my MySQL product table?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

585 Views

Let us first create a table −mysql> create table DemoTable    (    ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ProductQuantity int,    ProductPrice int    ); Query OK, 0 rows affected (0.19 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ProductQuantity, ProductPrice) values(10, 100); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(ProductQuantity, ProductPrice) values(5, 11); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(ProductQuantity, ProductPrice) values(3, 140); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(ProductQuantity, ProductPrice) values(2, 450); Query OK, 1 row affected ... Read More

MySQL Select when a grouped record has multiple matching strings?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

106 Views

You can use regular expression for this. Let us first create a table −mysql> create table DemoTable    (    ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ProductName varchar(20)    ); Query OK, 0 rows affected (0.19 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ProductName) values('Product-1'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(ProductName) values('Product2'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(ProductName) values('Product1'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(ProductName) values('Product-3'); Query OK, 1 row affected (0.05 sec) mysql> ... Read More

Lower case column names with MySQL SELECT?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

846 Views

Let us first create a table −mysql> create table DemoTable    (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserFirstName varchar(20),    UserLastName varchar(20),    UserAge int,    UserCountryName varchar(20)    ); Query OK, 0 rows affected (0.27 sec)Now check the description of table.mysql> desc DemoTable;This will produce the following output −+-----------------+-------------+------+-----+---------+----------------+ | Field           | Type        | Null | Key | Default | Extra | +-----------------+-------------+------+-----+---------+----------------+ | UserId          | int(11)     | NO   | PRI ... Read More

How can I find all columns where the column name length is greater than 5 in MySQL?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

156 Views

Use HAVING to find all columns where the column name length is greater than 5. This will produce the following output −+-------------------+-------------------------+ | TABLE_NAME        | COLUMN_NAME             | +-------------------+-------------------------+ | DemoTable         | UserId                  | | DemoTable         | EndDate                 | | DemoTable         | StartDate               | | DemoTable         | StudentFavouriteSubject | | DemoTable     ... Read More

MySQL Stored Procedure to create a table?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

3K+ Views

Following is the query to create a stored procedure that creates a table. Here, we are creating a table with three columns, one of them is Id −mysql> DELIMITER //    mysql> CREATE PROCEDURE Stored_Procedure_CreatingTable()    BEGIN       create table DemoTable       (       Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,       UserFirstName varchar(20),       UserLastName varchar(20)       );    END;    //    Query OK, 0 rows affected (0.16 sec) mysql> DELIMITER ;Now you can call stored procedure with the help of CALL command −mysql> call Stored_Procedure_CreatingTable(); ... Read More

Advertisements