![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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
846 Views
You can insert sequential number in MySQL using session variable. The syntax is as follows −SELECT @anyVariableName − = anyIntegerValue; UPDATE yourTableName SET yourColumnName = @anyVariableName − = @anyVariableName+IncrementStep;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SequentialNumberDemo -> ( -> SequentialNumber int not null -> ); Query OK, 0 rows affected (0.84 sec)Insert records in the table using insert command. The query is as follows −mysql> insert into SequentialNumberDemo values(100); Query OK, 1 row affected (0.11 sec) mysql> insert into SequentialNumberDemo values(10); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
992 Views
You can use below syntax to sum values of a single row −Case 1 − The following is the syntax if your column does not have NULL value −SELECT yourColumnName1+yourColumnName2+yourColumnName3+.......+N as anyVariableName FROM yourTableName;Case 2 − If your column has NULL value then use this syntax −SELECT IFNULL(yourColumnName1, 0)+ IFNULL(yourColumnName2, 0)+ IFNULL(yourColumnName3, 0)+.............+N AS anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SumValueOfSingleRow -> ( -> Id int NOT NULL AUTO_INCREMENT, -> FirstValue int, -> SecondValue int, -> ThirdValue ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
705 Views
Yes, you can use if() function from MySQL to reverse a boolean field. The syntax is as follows −UPDATE yourTableName SET yourBooleanColumnName = IF(yourBooleanColumnName, 0, 1);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ReverseBooleanField -> ( -> Id int NOT NULL AUTO_INCREMENT, -> isValid BOOLEAN -> , -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ReverseBooleanField(isValid) values(true); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
4K+ Views
You can use date_format() to convert varchar to date. The syntax is as follows −SELECT DATE_FORMAT(STR_TO_DATE(yourColumnName, 'yourFormatSpecifier'), 'yourDateFormatSpecifier') as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table VarcharToDate -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Created_Time varchar(100), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into VarcharToDate(Created_Time) values('12/1/2016'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
If you want to select a single row on the basis of primary key, use the WHERE clause. The syntax is as follows −SELECT * FROM yourTableName WHERE yourPrimaryKeyColumnName = someValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table selectWithPrimaryKey -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> Marks int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. The query is ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
355 Views
There is no difference between cast as Date and date() function in MySQL.The syntax of both cast() and date() is as follows −cast(yourDateTimeColumnName as Date) date(yourDateTimeColumnName)Both functions internally call Item_date_typecast. To check both the functions, let us create a table. The query to create a table is as follows −mysql> create table CastAsDateDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> ArrivalTime datetime, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.71 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
4K+ Views
You can SELECT ….WHERE id IN(..) using field() function to order with any column. The syntax is as follows −SELECT *FROM yourTableName WHERE yourColumnName IN(‘value1’, ’value2’, .......N) ORDER BY FIELD(yourColumnName, value1’, ’value2’, .......N);To understand the above syntax, let us create a table −mysql> create table SelectOrderbyField -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(30), -> Age int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into SelectOrderbyField(Name, Age) values('John', 23); Query OK, ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
8K+ Views
You can update field to add value to an existing value with the help of UPDATE and SET command. The syntax is as follows −UPDATE yourTableName SET yourColumnName = yourColumnName+integerValueToAdd WHERE yourCondition;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table addingValueToExisting -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(30), -> GameScore int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.58 sec)Insert records in the table using insert command. The query is as follows −mysql> insert ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
2K+ Views
The problem with UNIX_TIMESTAMP() function is that it returns an integer while we want to insert custom date i.e. not any integer part to MySQL date.Do not use UNIX_TIMESTAMP() for your column defined as TIMESTAMP because UNIX_TIMESTAMP() returns an integer.Check the UNIX_TIMESTAMP. The query is as follows −mysql> select UNIX_TIMESTAMP( '2019-01-09 15 −48 −23') AS IntegerValue;The following is the output −+--------------+ | IntegerValue | +--------------+ | 1547029103 | +--------------+ 1 row in set (0.00 sec)Look at the sample output, the UNIX_TIMESTAMP() function returns an integer of corresponding date and time.The syntax is as follows to insert custom date for ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
You can use ALTER command to remove primary key and auto_increment. The syntax is as follows −ALTER TABLE yourTableName DROP PRIMARY KEY, change yourColumnName yourColumnName data type;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removePrimaryKey -> ( -> StudentId int NOT NULL AUTO_INCREMENT, -> StudentFirstName varchar(20), -> StudentLastName varchar(20), -> PRIMARY KEY(StudentId) -> ); Query OK, 0 rows affected (0.47 sec)Check the description of table using DESC command. The syntax is as follows −desc yourTableName;Check the description of the table ... Read More