MySQLi Articles

Page 242 of 341

How select specific rows in MySQL?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 697 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

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

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 646 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

MySQL query to display ASC order in number column?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 354 Views

You can achieve this with the help of CAST() function. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Score int    ); Query OK,  0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score) values(10); Query OK,  1 row affected (0.19 sec) mysql> insert into DemoTable(Score) values(100); Query OK,  1 row affected (0.14 sec) mysql> insert into DemoTable(Score) values(11); Query OK,  1 row affected (0.13 sec) mysql> insert into DemoTable(Score) values(97); Query OK,  1 row affected (0.14 sec) mysql> insert into DemoTable(Score) values(78); Query OK,  1 row affected (0.13 sec) mysql> insert into DemoTable(Score) values(89); Query OK,  1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----+-------+ | Id | Score | +----+-------+ | 1 | 10 | ...

Read More

Listing all rows by group with MySQL GROUP BY?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 1K+ Views

To list all rows by group, you can use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20),    Value varchar(100)    ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Value) values('John', 'John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name, Value) values('Carol', 'Carol'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(Name, Value) values('John', 'Works'); Query OK, 1 row affected (0.13 sec) mysql> insert ...

Read More

How can I order in group but randomly with MySQL?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 373 Views

Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value char(1)    ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('X'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Value) values('Y'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Value) values('X'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable(Value) values('X'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(Value) values('Y'); Query OK, 1 ...

Read More

How to get MySQL combined field result?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 182 Views

You can use CONCAT() function from MySQL for this. Let us first create a table −mysql> create table DemoTable    (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientFirstName varchar(20),    ClientLastName varchar(20)    ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ClientFirstName, ClientLastName) values('John', 'Smith'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(ClientFirstName, ClientLastName) values('John', 'Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ClientFirstName, ClientLastName) values('Carol', 'Taylor'); Query OK, 1 row affected (0.13 sec) mysql> insert into ...

Read More

New line separator doesn't work for group_concat function in MySQL? How to use it correctly?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

To use new line separator in group_concat() function, follow the below syntax −select group_concat(concat_ws(' ', yourColumnName1, yourColumnName2) SEPARATOR "\r") from yourTableName;Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20),    LastName varchar(20)    ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName) values('John', 'Smith'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(FirstName, LastName) values('David', 'Miller'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(FirstName, LastName) values('John', 'Doe'); ...

Read More

Preserve select order within MySQL UNION?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 347 Views

It’s a good choice to use CASE statement. Do not use UNION. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ShippingDate datetime    ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ShippingDate) values('2019-04-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ShippingDate) values('2019-01-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(ShippingDate) values('2019-05-11'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ShippingDate) values('2018-12-31'); Query OK, 1 row ...

Read More

Implement Conditional MySQL Query in a stored procedure?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 768 Views

For conditional MySQL query, you can use IF ELSE concept in stored procedure. Let us first create a table −mysql> create table DemoTable1    (    Id int    ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1 values(20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1 values(30); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output ...

Read More

How to prevent a user from accessing a specific schema in MySQL?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 533 Views

To prevent a user from accessing a specific schema, you need to use delete command. Following is the syntax −DELETE FROM mysql.db WHERE Db IN("yourSpecificSchema", "yourSpecificSchema\_%")    AND User = "yourUserName" AND Host = "yourHostName";Let us implement the above syntax to prevent a user from accessing a specific schema. First of all, let us display all users and host from MySQL.user table.mysql> select user, host from MySQL.user;This will produce the following output −+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %       ...

Read More
Showing 2411–2420 of 3,404 articles
« Prev 1 240 241 242 243 244 341 Next »
Advertisements