
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

242 Views
To get Age using BirthDate column in a MySQL query, you can use datediff(). Let us first create a table:mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, DateOfBirth date ); Query OK, 0 rows affected (1.46 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(DateOfBirth) values('2010-01-21'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(DateOfBirth) values('1993-04-02'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(DateOfBirth) values('1999-12-01'); Query OK, 1 row affected (1.53 sec) mysql> insert into DemoTable(DateOfBirth) values('1998-11-16'); Query OK, 1 row ... Read More

834 Views
In order to select particular range of values in a MySQL table, you can use WHERE clause. Let us first create a table:mysql> create table DemoTable ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(200), CustomerAge int, isRegularCustomer bool ); Query OK, 0 rows affected (0.57 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(CustomerName, CustomerAge, isRegularCustomer)values('Chris', 24, true); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(CustomerName, CustomerAge, isRegularCustomer)values('Robert', 26, false); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(CustomerName, CustomerAge, isRegularCustomer)values('Mike', ... Read More

135 Views
Use DATE_FORMAT() and set the specifiers to display only the MonthName and Year. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AdmissionDate date ); Query OK, 0 rows affected (0.69 sec)Insert records in the table using insert command −mysql> insert into DemoTable(AdmissionDate) values('2013-04-21'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(AdmissionDate) values('2014-01-31'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(AdmissionDate) values('2016-09-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(AdmissionDate) values('2018-12-12'); Query OK, 1 row affected (0.11 sec) mysql> insert ... Read More

1K+ Views
To select first element of a comma-separated list, you can use SUBSTRING_INDEX(). Let us first create a table:mysql> create table DemoTable ( CSV_Value varchar(200) ); Query OK, 0 rows affected (0.81 sec)Following is the query to insert some records in the table using insert command. We have inserted records in the form of comma-separated integer list:mysql> insert into DemoTable values('10, 20, 50, 80'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('100, 21, 51, 43'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('1, 56, 103, 1090'); Query OK, 1 row affected (0.26 ... Read More

599 Views
In order to know the location of MySQL table data, you can use the below syntax −select @@datadir;You can also use SHOW VARIABLES command for this. Following is the syntax −show variables where Variable_name ='datadir';Let us implement the above syntaxes to know where MySQL table stores data −mysql> select @@datadir;This will produce the following output −+---------------------------------------------+ | @@datadir | +---------------------------------------------+ | C:\ProgramData\MySQL\MySQL Server 8.0\Data\ | +---------------------------------------------+ ... Read More

194 Views
To get maximum and minimum values in a single query, use the aggregate function min() and max(). Let us first create a table:mysql> create table DemoTable ( FirstValue int, SecondValue int ); Query OK, 0 rows affected (0.66 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values(10, 30); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(30, 60); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(100, 500); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(50, 80); Query OK, ... Read More

397 Views
To find strings beginning with a number, use Regular Expressions. Let us first create a table −mysql> create table DemoTable ( Id varchar(200) ); Query OK, 0 rows affected (0.59 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('123User'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('_$123User'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('User123456'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('0000User'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('&^*User'); Query OK, 1 row affected (0.24 sec)Display records ... Read More

674 Views
To get number of values that only appear once in a column, use GROUP BY HAVING. Let us first create a table:mysql> create table DemoTable ( Name varchar(20) ); Query OK, 0 rows affected (0.55 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values('Larry'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Larry'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

923 Views
To export specific column data in MySQL, use OUTFILE −select yourColumnName from yourTableName into outfile 'yourLocationOfFile’;Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(20), StudentLastName varchar(20) ); Query OK, 0 rows affected (0.54 sec)Insert records in the table using insert command −mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('John', 'Doe'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('David', 'Miller'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('John', 'Smith'); Query OK, 1 row affected (0.15 sec) mysql> insert into ... Read More

213 Views
To understand this, let us create a table with fields like ID, Customer Name, Items, Price. We will first multiply the items with price. After that the rows with similar records i.e. same customer name will get added.Let us first create a table:mysql> create table DemoTable ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(100), CustomerItems int, CustomerPrice int ); Query OK, 0 rows affected (0.54 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(CustomerName, CustomerItems, CustomerPrice)values('Larry', 3, 450); Query OK, 1 row affected (0.24 sec) mysql> ... Read More