
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 4218 Articles for MySQLi

1K+ 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

1K+ 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

6K+ 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

2K+ 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

533 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

5K+ 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

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

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

3K+ 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

25K+ Views
In MySQL, the ENUM is a data type that is used to create a column with a fixed set of values. It is helpful for the fields that have limited alternatives, such as categories, statuses, and color codes. However, as your application evolves, you might need to add more values to the list such as new colors. MySQL allows us to modify ENUM values without dropping and recreating the column. Adding New Value to an ENUM column For adding new values in an ENUM column in MySQL, you shall use the ALTER TABLE command with the MODIFY Keyword. For ... Read More