Found 4219 Articles for MySQLi

MySql how to display the records with latest ID in a table?

AmitDiwan
Updated on 26-Aug-2019 06:53:39

158 Views

Let us first create a table −mysql> create table DemoTable676(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Number int ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable676(Number) values(1000); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable676(Number) values(1839); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable676(Number) values(29894); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable676(Number) values(1264); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable676(Number) values(190); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More

How can I search within a table of comma-separated values in MySQL?

AmitDiwan
Updated on 26-Aug-2019 06:48:43

378 Views

To search within a table of comma-separated values, use LIKE operator. Let us first create a table −mysql> create table DemoTable675(Value text); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable675 values('10, 56, 49484, 93993, 211, 4594'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable675 values('4, 7, 1, 10, 90, 23'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable675 values('90, 854, 56, 89, 10'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable675 values('11, 22, 344, 67, 89'); Query OK, 1 row ... Read More

Is there a way to name columns in an INSERT statement in MySQL?

AmitDiwan
Updated on 26-Aug-2019 06:45:29

61 Views

Yes, we can name columns in an insert statement. Let us first create a table −mysql> create table DemoTable674(    StudentId int,    StudentFirstName varchar(100),    StudentLastName varchar(100)  ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable674 set StudentId=10, StudentFirstName='John', StudentLastName='Smith'; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable674 set StudentId=11, StudentFirstName='Carol', StudentLastName='Taylor'; Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable674 set StudentId=12, StudentFirstName='David', StudentLastName='Miller'; Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable674 set StudentId=13, StudentFirstName='Chris', StudentLastName='Brown'; Query OK, 1 ... Read More

MySQL query to select the values having multiple occurrence and display their count

AmitDiwan
Updated on 26-Aug-2019 06:37:17

1K+ Views

For this, use GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable673(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable673(Value) values(10); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable673(Value) values(20); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable673(Value) values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable673(Value) values(30); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable673(Value) values(20); Query OK, 1 ... Read More

MySQL Order by with case?

AmitDiwan
Updated on 26-Aug-2019 06:15:47

227 Views

For this, use order by nullif(). Let us first create a table −mysql> create table DemoTable672(    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(100),    CustomerAmount int ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('Chris', 560); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('Robert', null); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('', 450); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('David', 456); Query OK, 1 row affected ... Read More

Select particular type of columns beginning with a certain letter and concatenate the names

AmitDiwan
Updated on 26-Aug-2019 06:09:20

77 Views

For particular type of columns beginning with a certain letter, use LIKE. To concatenate the column names, use GROUP_CONCAT() as in the below syntax −SELECT group_concat(COLUMN_NAME separator ' , ') FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = "yourTableName" AND table_schema = "yourDatabaseName" AND column_name LIKE "yourSpecificLetter%";Let us first create a table −mysql> create table DemoTable671(    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(100),    ClientAge int,    ClientAddress varchar(200),    ClientCountryName varchar(100) ); Query OK, 0 rows affected (0.62 sec)Following is the query to select particular type of columns beginning with a certain letter and fetch all the column ... Read More

How to sort domain names in MySQL?

AmitDiwan
Updated on 26-Aug-2019 06:05:27

90 Views

To sort domain names, use the ORDER BY SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable670(DomainName text); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command. Here, we are inserting domain names −mysql> insert into DemoTable670 values('www.facebook.com'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable670 values('www.google.com'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable670 values('www.amazon.com'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable670;This will produce the following output −+------------------+ | DomainName       ... Read More

Query non-empty values of a row first in ascending order and then display NULL values

AmitDiwan
Updated on 21-Jan-2020 12:19:53

114 Views

For this, use ORDER BY ISNULL(). Let us first create a table −mysql> create table DemoTable669 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentScore int ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable669(StudentScore) values(45) ; Query OK, 1 row affected (0.80 sec) mysql> insert into DemoTable669(StudentScore) values(null); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable669(StudentScore) values(89); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable669(StudentScore) values(null); Query OK, 1 row affected (0.15 sec)Display all records from the table using select ... Read More

Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?

AmitDiwan
Updated on 23-Aug-2019 14:00:12

2K+ Views

Let us first create a table −mysql> create table DemoTable668(JoiningDate varchar(200)); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command. We have inserted date in the format yyyy-mm-ddThh:mm:ss.sssZ −mysql> insert into DemoTable668 values('2001-01-10T06:20:00.000Z'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable668 values('2019-07-20T04:00:00.000Z'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable668 values('2016-02-12T05:10:50.000Z'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable668;This will produce the following output −+--------------------------+ | JoiningDate             | +--------------------------+ | ... Read More

MySQL query to select closest date from today?

AmitDiwan
Updated on 23-Aug-2019 13:19:44

1K+ Views

Let’s say the current date is 2019-07-25. We will now see an example and create a table where ShippingDate is added in the table.Let us first create a table −mysql> create table DemoTable667(ShippingDate datetime); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command −mysql> insert into DemoTable667 values('2019-01-31'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable667 values('2019-07-19'); Query OK, 1 row affected (0.69 sec) mysql> insert into DemoTable667 values('2019-07-23'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable667 values('2019-08-24'); Query OK, 1 row affected (0.15 sec)Display all records from ... Read More

Advertisements