
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

878 Views
To create a tab delimited select statement, you can use CONCAT() function from MySQL. Following is the syntax:select concat(yourColumnName1, "\t", yourColumnName2) AS anyAliasName from yourTableName;Let us first create a table:mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.81 sec)Following is the query to insert records in the table using insert command:mysql> insert into DemoTable(FirstName, LastName) values('John', 'Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(FirstName, LastName) values('Carol', 'Taylor'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(FirstName, LastName) ... Read More

172 Views
Let us first create a table −mysql> create table DemoTable ( StudentId int ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(343898456); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(222333444); Query OK, 1 row affected (0.22 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-----------+ | StudentId | +-----------+ | 343898456 | | 222333444 | +-----------+ 2 rows in set (0.00 sec)Here is the query to create view ... Read More

7K+ Views
Let us first create a table with columns for which we will calculate the difference in a new column −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, LowValue int, HighValue int ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(LowValue, HighValue) values(100, 200); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(LowValue, HighValue) values(300, 700); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(LowValue, HighValue) values(1000, 2000); Query OK, 1 row affected (0.13 sec)Following is the query to ... Read More

167 Views
To perform custom sort by field value in MySQL, use the FIELD() method in ORDER BY. Let us first create a table:mysql> create table DemoTable (StudentId int); Query OK, 0 rows affected (0.58 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(110); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(70); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(120); Query ... Read More

4K+ Views
To create a table with a space in the table name in MySQL, you must use backticks otherwise you will get an error.Let us first see what error will arise by creating a table with a space in the name i.e. “Demo Table” table name below:mysql> create table Demo Table ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeFirstName varchar(20), EmployeeLastName varchar(20), EmployeeAge int, EmployeeSalary int, EmployeeAddress varchar(200) ); ERROR 1064 (42000): You have an error in your syntax; check the manual that corresponds to your MySQL server version for the right syntax to ... Read More

2K+ Views
To convert date from 'dd/mm/yyyy' to 'yyyymmdd', you can use the date_format() method. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Admissiondate varchar(200) ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Admissiondate) values('21/10/2014'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(Admissiondate) values('01/12/2016'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Admissiondate) values('31/01/2017'); Query OK, 1 row affected (0.14 sec)Following is the query to display all records from the table using select statement ... Read More

13K+ Views
To add column to MySQL query and give it a value, use the below syntax −select yourColumnName1, yourColumnName2, .....N ,yourValue AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName) values('John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(FirstName) values('Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

1K+ Views
To extract the User ID only from MySQL, you can use SUBSTRING_INDEX(), which extracts the part of a string from the Username to get the User ID. Let us first display the user −mysql> SELECT USER();This will produce the following output −+----------------+ | USER() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)Let us now extract the UserID only −mysql> SELECT SUBSTRING_INDEX(USER(), '@', 1);This will produce the following output −+-------------------------------+ | SUBSTRING_INDEX(USER(), '@', 1) | +-------------------------------+ | root ... Read More

315 Views
To change a specific char in a MySQL string, you can use CONCAT() along with SUBSTRING().Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value varchar(200) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('98764'); Query OK, 1 row affected (0.17 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----+-------+ | Id | Value | +----+-------+ | 1 | 98764 | +----+-------+ ... Read More

3K+ Views
You can use CAST() with MAX() for this. Since the string is filled with string and integer, fir example, “STU201”, therefore we need to use CAST().Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentBookCode varchar(200) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentBookCode) values('STU201'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentBookCode) values('STU202'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentBookCode) values('STU203'); Query OK, 1 row affected (0.20 sec) mysql> ... Read More