Found 4219 Articles for MySQLi

MySQL RegEx to find lines containing N semi-colons?

AmitDiwan
Updated on 09-Oct-2019 11:15:40

176 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY ,    Title text ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Title) values('This is; a; MySQL;Tutorial'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Title) values('Java is; an;Object Oriented'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Title) values('MongoDB ; is;a; database'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following ... Read More

How to find tables with a specific column name in MySQL?

AmitDiwan
Updated on 09-Oct-2019 11:12:56

984 Views

To find column names, use information_schema.columns. Following is the syntax −select distinct table_name from information_schema.columns where column_name like '%yourSearchValue%' and table_schema=database();Let us implement the above syntax in order to find column names across various table. Here, we want only table names with a specific column name word “Client” −mysql> select distinct table_name    from information_schema.columns    where column_name like '%Client%'    and table_schema=database();This will produce the following output −+----------------+ | table_name    | +----------------+ | demotable449 | | demotable450 | | demotable461 | | demotable517 | | demotable529 | ... Read More

Adding characters in values for an existing int column in MySQL?

AmitDiwan
Updated on 09-Oct-2019 11:08:26

316 Views

To add characters to an existing int column values, use MySQL CONCAT(). Let us first create a table −mysql> create table DemoTable (    Amount int ); Query OK, 0 rows affected (1.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(709); Query OK, 1 row affected (0.67 sec) mysql> insert into DemoTable values(34560); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values(90854); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(3456); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select ... Read More

Pull MySQL records for the last 60 minutes?

AmitDiwan
Updated on 09-Oct-2019 10:50:28

605 Views

To pull records for the last 60 minutes, use MySQL INTERVAL as shown in the below syntax −select *from yourTableName where yourColumnName > now() - interval 60 minute;Let us first create a table −mysql> create table DemoTable (    ArrivalTime datetime ); Query OK, 0 rows affected (0.61 sec)Let us find the current date −mysql> select now(); +-----------------------+ | now()                 | +-----------------------+ | 2019-09-17 00 :04 :54 | +-----------------------+ 1 row in set (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-09-16 08 :00 :00'); Query ... Read More

How to select records beginning with certain numbers in MySQL?

AmitDiwan
Updated on 09-Oct-2019 10:48:05

3K+ Views

The optimal solution to select records beginning with certain numbers, use MySQL LIKE operator. Let us first create a table −mysql> create table DemoTable (    ClientId bigint,    ClientName varchar(40) ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(23568777, 'Chris Brown'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(9085544, 'John Doe'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(9178432, 'John Doe'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(9078482, 'David Miller'); Query OK, 1 row ... Read More

Delete selective multiple records using MySQL DELETE query

AmitDiwan
Updated on 09-Oct-2019 10:45:58

400 Views

For selective multiple records, use MySQL IN(). To delete them, use MySQL DELETE. Let us first create a table −mysql> create table DemoTable (    ClientId varchar(40),    ClientName varchar(50) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('CLI-101', 'Chris'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('CLI-110', 'Adam'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('CLI-220', 'Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-120', 'Bob'); Query OK, 1 row affected (0.53 sec) mysql> insert ... Read More

How to check if any of the strings in a column contains a specific string in MySQL?

AmitDiwan
Updated on 09-Oct-2019 10:41:16

1K+ Views

For this, use CONCAT() along with LIKE operator. Let us first create a table −mysql> create table DemoTable (    Name varchar(40) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Johnson'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.12 sec)Display all records ... Read More

Perform NAND/NOR operations in MySQL

AmitDiwan
Updated on 09-Oct-2019 10:38:33

777 Views

Let us first see how we can perform NAND/NOR operations in MySQL. The concept is as follows −NAND= NOT( yourColumnName1 AND yourColumnName2) NOR=NOT( yourColumnName1 OR yourColumnName2)Let us first create a table −mysql> create table DemoTable (    Value1 boolean ,    Value2 boolean ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(true, true); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(false, false); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(false, true); Query OK, 1 row affected (0.10 sec) mysql> insert ... Read More

Display records from the current date till rest of the same month in MySQL?

AmitDiwan
Updated on 09-Oct-2019 10:35:40

82 Views

Let us first create a table −mysql> create table DemoTable (    BookingDate date ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-09-21'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2018-09-10'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-09-10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-08'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2016-09-18'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select ... Read More

MySQL query to group by names and display the count in a new column

AmitDiwan
Updated on 09-Oct-2019 10:33:24

644 Views

Use GROUP BY with the COUNT() method. Group the names with GROUP BY and count using the COUNT() method. Let us first create a table −mysql> create table DemoTable (    Name varchar(30) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.07 sec) mysql> insert into ... Read More

Advertisements