- 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
566 Views
Let us first create a table to increase and adecrease row value by 1. The following is the query −mysql> create table IncrementAndDecrementValue −> ( −> UserId int, −> UserScores int −> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into IncrementAndDecrementValue values(101, 20000); Query OK, 1 row affected (0.13 sec) mysql> insert into IncrementAndDecrementValue values(102, 30000); Query OK, 1 row affected (0.20 sec) mysql> insert into IncrementAndDecrementValue values(103, 40000); Query OK, 1 row affected (0.11 sec)Display all records ... Read More
635 Views
You can increase and decrease row value by 1 in MySQL using UPDATE command. The syntax is as follows −UPDATE yourTableName set yourColumnName = yourColumnName-1 where condition;Let us create a table to decrease row value by 1. The following is the query −mysql> create table IncrementAndDecrementValue −> ( −> UserId int, −> UserScores int −> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into IncrementAndDecrementValue values(101, 20000); Query OK, 1 row affected (0.13 sec) mysql> insert into IncrementAndDecrementValue values(102, 30000); ... Read More
8K+ Views
You can use in-built function UPPER() from MySQL to change a lower case to upper case. The syntax is as follows with select statement.SELECT UPPER(‘yourStringValue’);The following is an example showing string in lower case −mysql> select upper('john');Here is the output displaying string in upper case −+---------------+ | upper('john') | +---------------+ | JOHN | +---------------+ 1 row in set (0.00 sec)If you already have a table with a lower case value, then you can use the UPPER() function with update command. The syntax is as follows −UPDATE yourTableName set yourColumnName = UPPER(yourColumnName);To understand the above concept, let ... Read More
1K+ Views
To get average on time column, use the below syntax. It will give the average in time format −SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(yourColumnName))) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The following is the query −mysql> create table AverageOnTime −> ( −> PunchInTime time −> ); Query OK, 0 rows affected (0.61 sec)Insert time values in the table using insert command. The query to insert records is as follows −mysql> insert into AverageOnTime values('00:00:40'); Query OK, 1 row affected (0.20 sec) mysql> insert into AverageOnTime values('00:02:50'); Query OK, 1 row affected (0.15 sec) ... Read More
3K+ Views
To extract first word from a field, use in-built SUBSTRING_INDEX() function. The syntax is as follows −SELECT SUBSTRING_INDEX(yourColumnName, ’ ‘, 1) as anyVariableName from yourTableName;In the above query, if you use -1 in place of 1 then you will get the last word. To understand the above concept, let us create a table. The following is the query to create a table.mysql> create table FirstWordDemo −> ( −> AllWords longtext −> ); Query OK, 0 rows affected (0.83 sec)Now insert some words in the table using insert command. The query is ... Read More
3K+ Views
To display the value of a variable, you can use select statement. The syntax is follows −SELECT @yourVariableName;Let us first create a variable. This can be done using SET command. The following is the syntax to create a variable −SET @yourVariableName = yourValue;Let us check the above syntax to create a variable and display the value of created variable.The following is the query to create a variable −mysql> set @FirstName = 'Bob'; Query OK, 0 rows affected (0.04 sec)Now you can display the value of a variable using select statement. The query is as follows −mysql> select @FirstName;The following is ... Read More
398 Views
You can update MySQL with IF condition as well as CASE statement. For this purpose, let us first create a table. The query to create a table −mysql> create table UpdateWithIfCondition −> ( −> BookId int, −> BookName varchar(200) −> ); Query OK, 0 rows affected (0.60 sec)Now you can insert records in the table using insert command. The query is as follows −mysql> insert into UpdateWithIfCondition values(1000, 'C in Depth'); Query OK, 1 row affected (0.12 sec) mysql> insert into UpdateWithIfCondition values(1001, 'Introduction to Java'); Query OK, 1 row affected (0.14 sec)Display all records ... Read More
388 Views
To convert int to current format, use CONCAT() with FORMAT() function from MySQL.The syntax is as follows −SELECT CONCAT(‘CurrencySymbol’, FORMAT(yourColumnName, valueAfterDecimal)) as AnyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table −mysql> create table AddingCurrencySymbolDemo −> ( −> Amount int −> ); Query OK, 0 rows affected (1.50 sec)Insert records in the table using insert command. The query is as follows −mysql> insert into AddingCurrencySymbolDemo values(250); Query OK, 1 row affected (0.22 sec) mysql> insert into AddingCurrencySymbolDemo values(500); Query OK, 1 ... Read More
376 Views
You can change the current count of an auto_increment in MySQL using ALTER command.The syntax is as follows −ALTER TABLE yourTableName AUTO_INCREMENT = IntegerValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table changeCurrentAutoIncrementValue −> ( −> CurrentCount int auto_increment, −> PRIMARY KEY(CurrentCount) −> ); Query OK, 0 rows affected (0.60 sec)Insert records in the table using select statement. The auto_increment by default starts from 1 and increments by 1. The query to insert record is as follows −mysql> insert into changeCurrentAutoIncrementValue values(); Query ... Read More
3K+ Views
To add days to a date, you can use DATE_ADD() function from MySQL. The syntax is as follows to add days to a date −INSERT INTO yourTableName VALUES(DATE_ADD(now(), interval n day));In the above syntax, you can use curdate() instead of now(). The curdate() will store only date while now() will store both date and time.Here is the demo of both the functions. To understand the above syntax, let us create a table.mysql> create table addingDaysDemo −> ( −> yourDateTime datetime −> ); Query OK, 0 rows affected (1.09 sec)Use both the ... Read More