![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4219 Articles for MySQLi
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
6K+ Views
To do a count on a union i.e. to get the count of the UNION result, use the below syntax −SELECT COUNT(*) FROM ( SELECT yourColumName1 from yourTableName1 UNION SELECT yourColumName1 from yourTableName2 ) anyVariableName;To understand the above syntax, let us create two tables with some records. The query to create a table is as follows −mysql> create table union_Table1 -> ( -> UserId int -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into union_Table1 values(1); Query OK, 1 row affected (0.18 sec) ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
357 Views
You can use in-built function CONCAT() from MySQL. The syntax is as follows −SELECT CONCAT(('(', yourColumnName1, ', ', yourColumnName2, ', ', yourColumnName3, ...N')')as anyVariableName from yourTableName;To understand the above syntax, let us first create a table. The query to create a table is as follows −mysql> create table Concatenation_OperatorDemo -> ( -> -> VendorId int, -> VendorName varchar(100), -> VendorCountry varchar(100) -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into Concatenation_OperatorDemo values(101, 'Carol', 'US'); Query OK, 1 row affected (0.19 sec) mysql> insert ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
927 Views
The syntax for updating a column with random number between 1-3 is is as follows −update yourTableName set yourColumnName=FLOOR(1+RAND()*3);To understand the above syntax, let us first create a table. The query to create a table is as follows −mysql> create table UpdateNumber1To3 -> ( -> MyNumber int -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into UpdateNumber1To3 values(100); Query OK, 1 row affected (0.16 sec) mysql> insert into UpdateNumber1To3 values(140); Query OK, 1 row affected (0.25 sec) mysql> insert into UpdateNumber1To3 values(130); ... Read More
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
46 Views
Let’s say we have a database “business” with number of tables. If you want to Get the fields in each constraint, then use the below query.The below query is to get the fields in each one of those constraints −mysql> select * −> from information_schema.key_column_usage −> where constraint_schema = 'business';The following is the output −+--------------------+-------------------+--------------------------+---------------+--------------+------------------------------+--------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ | CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | POSITION_IN_UNIQUE_CONSTRAINT | REFERENCED_TABLE_SCHEMA | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME | +--------------------+-------------------+--------------------------+---------------+--------------+------------------------------+--------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ | def ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
8K+ Views
To store query result in a variable with MySQL, use the SET command. The syntax is as follows −SET @anyVariableName = ( yourQuery);To understand the above concept, let us create a table. The following is the query to create a table −mysql> create table QueryResultDemo −> ( −> Price int −> ); Query OK, 0 rows affected (0.59 sec)Now let us insert some records into the table. The following is the query to insert records −mysql> insert into QueryResultDemo values(100); Query OK, 1 row affected (0.17 sec) mysql> insert into QueryResultDemo values(20); Query OK, 1 row ... Read More
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
1K+ Views
You can compare DATE string with string from DATETIME field with the help of DATE() function in MySQL.The syntax is as follows −select *from yourTableName where DATE(yourColumnName) = ’anyDateString’;To understand the above syntax, let us create a table and set some datetime values in the table. The query to create a table −mysql> create table DateTimeDemo −> ( −> ArrivalTime datetime −> ); Query OK, 0 rows affected (0.61 sec)Let us insert some records in the table with the help of insert command. The following is the query to insert records ... Read More
![Rishi Rathor](https://www.tutorialspoint.com/assets/profiles/13563/profile/60_89283-1512714754.jpg)
517 Views
To get difference between two timestamps in seconds, use two in-built functions TIME_TO_SEC() and TIMEDIFF() in MySQL. The syntax is as follows −select time_to_sec(timediff(yourCoulnName1, yourCoulnName2)) as anyVariableName from yourTableName;To understand the above concept, let us first create a table. The query to create a table.mysql> create table TimeToSecond −> ( −> MyTime timestamp, −> YourTime timestamp −> ); Query OK, 0 rows affected (0.48 sec)Now you can insert some datetime values in the table. The query is as follows −mysql> insert into TimeToSecond values('2016-05-10 10:02:00', '2016-05-10 10:00:00'); Query ... Read More
![Jennifer Nicholas](https://www.tutorialspoint.com/assets/profiles/13569/profile/60_88876-1512715262.jpg)
7K+ Views
To concatenate two columns, use CONCAT() function in MySQL. The syntax is as follows −select CONCAT(yourColumnName1, ' ', yourColumnName2) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table concatenateTwoColumnsDemo −> ( −> StudentId int, −> StudentName varchar(200), −> StudentAge int −> ); Query OK, 0 rows affected (1.06 sec)Now you can insert some records in the table. The query to insert records is as follows −mysql> insert into concatenateTwoColumnsDemo values(1, 'Sam', 21); Query OK, 1 row affected (0.18 sec) ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
425 Views
To front pad zip code with 0, use LPAD() function in MySQL. The syntax is as follows −SELECT LPAD(yourColumnName, columnWidth+1, '0') as anyVariableName from yourTableName;To understand the above concept of LPAD() to add front pad zip code with 0, let us create a table. One of the columns of the table is Zip Code. The following is the query to create a table.mysql> create table ZipCodePadWithZeroDemo −> ( −> Name varchar(200), −> YourZipCode int(6) −> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table. The query to insert records is as follows ... Read More
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
1K+ Views
To check how many users are present in MySQL, use MySQL.user table. The syntax is as follows to check how many users are present.mysql> SELECT User FROM mysql.user;The following output displays the users −+------------------+ | User | +------------------+ | Mac | | Manish | | mysql.infoschema | | mysql.session | | mysql.sys | | root ... Read More