Found 4219 Articles for MySQLi

How to make MySQL display results in a single line?

AmitDiwan
Updated on 11-Dec-2019 06:05:58

2K+ Views

For this, you can use group_concat(). Let us first create a table −mysql> create table DemoTable1507    -> (    -> Name varchar(20),    -> PaperSet int    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1507 values('Chris', 111); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable1507 values('David', 112); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1507 values('Mike', 111); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1507 values('Bob', 113); Query OK, 1 row affected (0.14 sec)Display all records from ... Read More

Remove space between two words in MySQL?

AmitDiwan
Updated on 11-Dec-2019 06:03:57

270 Views

For this, you can use REPLACE(). Let us first create a table −mysql> create table DemoTable1506    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1506 values('This is MySQL'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1506 values('This is Java language'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1506 values('This is MongoDB NoSQL database'); Query OK, 1 row affected (0.60 sec)Display all records from the table using select statement −mysql> select * from DemoTable1506;This will ... Read More

How do I force the column alias to be of specific data type in MySQL?

AmitDiwan
Updated on 11-Dec-2019 06:01:36

221 Views

For this, you can use CASE statement. Let us first create a table −mysql> create table DemoTable1505    -> (    -> Value integer unsigned,    -> Status tinyint(1)    -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1505 values(20, 0); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1505 values(45, 1); Query OK, 1 row affected (0.08 sec)Display all records from the table using select statement −mysql> select * from DemoTable1505;This will produce the following output −+-------+--------+ | Value | Status | +-------+--------+ |   ... Read More

Swap a specific column value in MySQL

AmitDiwan
Updated on 11-Dec-2019 06:00:12

192 Views

Let us first create a table table −mysql> create table DemoTable1504    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1504 values(101, 'Chris'); Query OK, 1 row affected (0.63 sec) mysql> insert into DemoTable1504 values(102, 'Bob'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1504 values(103, 'David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1504 values(104, 'Mike'); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement ... Read More

Passing NULL to MySQL for auto increment?

AmitDiwan
Updated on 11-Dec-2019 05:58:03

712 Views

Yes, we can pass NULL as in the below syntax −insert into yourTableName values(NULL, yourValue1, yourValue2, ...N);Let us first create a table −mysql> create table DemoTable1503    -> (    -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(20),    -> ClientAge int    -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command. Since we have set NOT NULL above, it won’t affect auto_increment −mysql> insert into DemoTable1503 values(NULL, 'Chris', 25); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1503 values(NULL, 'David', 28); Query OK, 1 row ... Read More

MySQL query for sorting on a columns partial value like number in “John_120 “

AmitDiwan
Updated on 11-Dec-2019 05:56:26

103 Views

For this, you can use SUBSTRING_INDEX() along with ORDER BY. Let us first create a table −mysql> create table DemoTable1502    -> (    -> StudentId varchar(40)    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1502 values('John_120'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1502 values('John_201'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1502 values('Mike_178'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1502 values('Bob_198'); Query OK, 1 row affected (0.36 sec)Display all records from the table using select ... Read More

MySQL query to select multiple rows effectively?

AmitDiwan
Updated on 11-Dec-2019 05:53:17

2K+ Views

You need to use index to select multiple rows effectively. Let us first create a table −mysql> create table DemoTable1501    -> (    -> Id int NOT NULL PRIMARY KEY,    -> URL text    -> ); Query OK, 0 rows affected (0.62 sec)Here is the query to create index −mysql> create index id_index on DemoTable1501(Id); Query OK, 0 rows affected (0.23 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1501 values(101, 'www.facebook.com'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1501 values(110, 'www.google.com'); Query OK, 1 ... Read More

MySQL query to sum up values of rows and sort the result?

AmitDiwan
Updated on 11-Dec-2019 05:46:53

161 Views

For this, you can use GROUP BY along with ORDER BY clause. Let us first create a table −mysql> create table DemoTable1499    -> (    -> StudentName varchar(20),    -> StudentMarks int    -> ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1499 values('Chris', 56); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1499 values('David', 78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1499 values('Bob', 98); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1499 values('Chris', 45); Query OK, 1 row ... Read More

Duplicate a MySQL Database without using mysqldump?

AmitDiwan
Updated on 11-Dec-2019 05:44:21

620 Views

To duplicate a MySQL database, the syntax is as follows −create table yourdatabaseName1.yourTableName1 select * from yourdatabaseName2.yourTableName2;Let us first create a table −mysql> use sample; Database changed mysql> create table DemoTable101    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.45 sec)Insert some records in the table using insert command−mysql> insert into DemoTable101 values(101, 'Sam'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable101 values(102, 'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable101 values(103, 'David'); Query OK, 1 row affected (0.11 sec)Display all records ... Read More

How to use MySQL LIKE query to search a column value with % in it?

AmitDiwan
Updated on 11-Dec-2019 05:41:59

757 Views

To search a column value with %, the syntax is as follows −select * from yourTableName  where yourColumnName LIKE '\%%';Let us first create a table −mysql> create table DemoTable1497    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert −mysql> insert into DemoTable1497 values('%JohnSmith'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1497 values('DavidMiller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1497 values('CarolTaylor%'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1497 values('%DavidMiller'); Query OK, 1 row affected (0.12 ... Read More

Advertisements