Found 4219 Articles for MySQLi

What is ROW_NUMBER() in MySQL?

Ankith Reddy
Updated on 25-Jun-2020 08:13:35

2K+ Views

Row_NUMBER() included from MySQL version 8.0. It is a type of window function. This can be used to assign a sequence number for rows. To understand, create a table with the help of CREATE pcommand −Creating a tablemysql> CREATE table rowNumberDemo -> ( -> FirstName varchar(100) -> ); Query OK, 0 rows affected (0.92 sec)Inserting recordsmysql> INSERT into rowNumberDemo values('john'); Query OK, 1 row affected (0.17 sec) mysql> INSERT into rowNumberDemo values('john'); Query OK, 1 row affected (0.29 sec) mysql> INSERT into rowNumberDemo values('Bob'); Query OK, 1 row affected (0.13 sec) mysql> INSERT into rowNumberDemo values('Smith'); Query ... Read More

Simplest way to copy data from one table to another new table in MySQL?

Arjun Thakur
Updated on 25-Jun-2020 08:14:27

905 Views

To copy data from one table to another table, firstly we will create a table.Creating first table −mysql> CREATE table FirstTable -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)After creating a table, we will insert records.mysql> INSERT into FirstTable values(1, 'john'); Query OK, 1 row affected (0.20 sec) mysql> INSERT into FirstTable values(2, 'Smith'); Query OK, 1 row affected (0.21 sec)We can display all the records with the help of SELECT statement −mysql> SELECT * From FirstTable; The following is the output+------+-------+ | id | name | ... Read More

Pagination using MySQL LIMIT, OFFSET?

George John
Updated on 25-Jun-2020 07:53:00

6K+ Views

Firstly, we need to create a table with some records, then we will use pagination with the help of limit and offset.Creating a table with the help of CREATE command. The query is as follows −mysql> CREATE table limitoffsetDemo -> ( -> id int, -> FisrtName varchar(200) -> ); Query OK, 0 rows affected (0.45 sec)After creating a table, we will insert records with the help of INSERT command.Inserting recordsmysql> INSERT into limitoffsetDemo values(1, 'John'); Query OK, 1 row affected (0.11 sec) mysql> INSERT into limitoffsetDemo values(2, 'Bob'); Query OK, 1 row affected (0.16 sec) mysql> INSERT into ... Read More

Advantages of using MySQLi over MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

3K+ Views

MySQLi is also known as MySQL improved Extension. It is a relational SQL database management system. It is often used inside PHP to provide an interface with the MySQL databases. Some of the reasons why MySQLi is famous are given below − MySQLi uses the standard form of the SQL language. MySQLi is free as it is released under an open source license. MySQLi can be easily used with PHP which is the most famous language for web development. MySQLi is a very powerful language and it can handle the functionality of powerful database packages. MySQLi can work with ... Read More

Find and Replace text in the entire table using a MySQL?

Arjun Thakur
Updated on 25-Jun-2020 07:54:10

297 Views

The text can be found and replaced with the help of the replace() function. It is explained with the help of the following steps −First, a table is created with the help of the create command which is given as follows −mysql> CREATE table FindAndReplaceDemo -> ( -> FirstName varchar(200) -> ); Query OK, 0 rows affected (0.43 sec)After creating the above table, the records are inserted with the help of the insert command. This is given below −mysql> INSERT into FindAndReplaceDemo values('john'); Query OK, 1 row affected (0.15 sec) mysql> INSERT into FindAndReplaceDemo values('smith'); Query OK, 1 row ... Read More

How to display all the tables in MySQL with a storage engine?

Ankith Reddy
Updated on 25-Jun-2020 08:03:59

96 Views

We can display all the tables with the help of the WHERE clause. The syntax for that is as follows −SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = 'InnoDB';Now, the above syntax is applied to the given query −mysql> SELECT * from INFORMATION_SCHEMA.TABLES WHERE engine = 'InnoDB';The following is the output obtained −+---------------+--------------+---------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+---------------------------------------+-----------------------------------------+ | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT | +---------------+--------------+---------------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+---------------------------------------+-----------------------------------------+ | def | mysql ... Read More

How to remove leading and trailing whitespace in a MySQL field?

George John
Updated on 25-Jun-2020 08:06:34

839 Views

To remove leading and trailing space, we can use the trim() in MySQL. Firstly, we will create a table with the help of CREATE command.Creating a table −mysql> CREATE table TrailingANdLeadingDemo -> ( -> SpaceTrailLead varchar(100) -> ); Query OK, 0 rows affected (0.57 sec)After creating a table, we will insert a record with the help of INSERT command. Let us insert a record with leading and trailing space −mysql> INSERT into TrailingANdLeadingDemo values(' john '); Query OK, 1 row affected (0.12 sec)We can display all the records with the help of SELECT commandDisplaying recordsmysql> SELECT * from TrailingANdLeadingDemo; The ... Read More

How to use Straight Join in MySQL?

Arjun Thakur
Updated on 25-Jun-2020 08:08:13

536 Views

The straight join in MySQL works like inner join or join. This means that it returns only the matching rows. Firstly, we need to understand Straight join in MySQL. For that, we need to create two tables and relate both the tables with foreign key constraints.Here is the first tablemysql> CREATE table ForeignTableDemo -> ( -> Id int, -> Name varchar(100), -> FK int -> ); Query OK, 0 rows affected (0.47 sec)Here is the second table −mysql> CREATE table PrimaryTableDemo -> ( -> FK int, -> Address varchar(100), -> primary key(FK) -> ); Query OK, 0 rows affected (0.47 ... Read More

How to measure actual MySQL query time?

Ankith Reddy
Updated on 25-Jun-2020 08:08:48

4K+ Views

To measure actual MySQL query time, we can use the concept of profiling that must be set to 1 before executing the query.The order must be like this.Set profiling to 1 Then execute query Then show profilesNow, I am applying the above order to get the actual MySQL query time −mysql> SET profiling = 1; Query OK, 0 rows affected, 1 warning (0.00 sec)After that I am executing the following query −mysql> SELECT * from MilliSecondDemo; The following is the output+-------------------------+ | MyTimeInMillSec | +-------------------------+ | 2018-10-08 15:19:50.202 | +-------------------------+ 1 row ... Read More

How to save time in milliseconds in MySQL?

Chandu yadav
Updated on 25-Jun-2020 08:09:10

3K+ Views

To save time in milliseconds, we can use now(3) function because “milli 3” can be used for te same purpose. Firstly, I will create a table with the help of CREATE command −mysql> CREATE table MilliSecondDemo -> ( -> MyTimeInMillSec datetime(3) -> ); Query OK, 0 rows affected (0.70 sec)Inserting record into the table −mysql> INSERT into MilliSecondDemo values(now(3)); Query OK, 1 row affected (0.98 sec)Let us now view the table records −mysql> SELECT * from MilliSecondDemo; The following is the output+-------------------------+ | MyTimeInMillSec | +-------------------------+ | 2018-10-08 15:19:50.202 | +-------------------------+ 1 row in set (0.00 sec)

Advertisements