
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 4381 Articles for MySQL

243 Views
You can get max and second max salary from an Employee table using subquery.Let us first create a table. The query to create a table is as follows −mysql> create table EmployeeMaxAndSecondMaxSalary -> ( -> EmployeeId int, -> Employeename varchar(20), -> EmployeeSalary int -> ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into EmployeeMaxAndSecondMaxSalary values(1, 'John', 34566); Query OK, 1 row affected (0.20 sec) mysql> insert into EmployeeMaxAndSecondMaxSalary values(2, 'Bob', 56789); Query OK, 1 row affected (0.17 sec) mysql> insert into EmployeeMaxAndSecondMaxSalary values(3, ... Read More

662 Views
To get the output MySQL query result in CSV format, use concat(). The syntax is as follows −mysql> select concat(StudentId, ', ', StudentName, ', ', StudentAge) as CSVFormat from CSVFormatOutputs;To understand the above syntax, let us create a table. The query to create a table is as follows−mysql> create table CSVFormatOutputs -> ( -> StudentId int not null auto_increment, -> StudentName varchar(20), -> StudentAge int, -> PRIMARY KEY(StudentId) -> ); Query OK, 0 rows affected (1.15 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into CSVFormatOutputs(StudentName, ... Read More

466 Views
You can get max and second max salary from an Employee table using LIMIT OFFSET. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ....N from yourTableName ORDER BY yourColumnName desc limit 2 offset 0;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table EmployeeMaxAndSecondMaxSalary -> ( -> EmployeeId int, -> Employeename varchar(20), -> EmployeeSalary int -> ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into EmployeeMaxAndSecondMaxSalary values(1, 'John', 34566); Query OK, 1 row ... Read More

404 Views
You can add column values without using aggregate function like sum(). For that, the syntax is as follows −SELECT *, (yourColumnName1+yourColumnName2+yourColumnName3, ....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 AddingColumnDemo -> ( -> StudentId int, -> StudentName varchar(20), -> MathMarks int, -> PhysicsMarks int, -> ChemistryMarks int -> ); Query OK, 0 rows affected (0.82 sec)Insert records in the table using insert command. The query is as follows −mysql> insert into AddingColumnDemo values(1, 'John', 35, ... Read More

843 Views
To get the last index, use the SUBSTRING_INDEX() function from MySQL. The syntax is as follows −SELECT yourColumnName1, ...N, SUBSTRING_INDEX(yourColumnName, ’yourDelimiter’, -1)as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table LastIndexString -> ( -> Id int, -> yourURL text -> ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using INSERT command. The query is as follows −mysql> insert into LastIndexString values(1, 'https −//www.example.com/home.html'); Query OK, 1 row affected (0.26 sec) mysql> insert into LastIndexString values(2, ... Read More

369 Views
SQLite is an open source database and is serverless that needs no configuration. Entire database is a single disk file that can be placed anywhere in operating system's file system. SQLite commands are similar to standard SQL. SQLite is extensively used by applications such as browsers for internal data storage. It is also convenient data storage for embedded devices.Standard Python library has in built support for SQLite database connectivity. It contains sqlite3 module which is a DB-API V2 compliant module written by Gerhad Haring. It adheres to DB-API 2.0.The DB-API has been defined in accordance with PEP-249 to ensure similarity ... Read More

2K+ Views
The best data type for unix_timestamp in MySQL is integer. The integer data type is as followsint(11);The integer data type is useful for condition checking like ( > , create table UnixTime -> ( -> DueTime datetime -> ); Query OK, 0 rows affected (0.55 sec)Insert records in the form of date using insert command. The query is as followsmysql> insert into UnixTime values(now()); Query OK, 1 row affected (0.15 sec) mysql> insert into UnixTime values('2010-10-14'); Query OK, 1 row affected (0.15 sec) mysql> insert into UnixTime values('2020-09-24'); Query ... Read More

651 Views
To select yesterday’s date, use the subdate() function from MySQL. The syntax is as followsselect subdate(yourDatetimeColumnName) as anyVariableName from yourTableName;To understand the above syntax, let us create a tablemysql> create table YesterdayDateDemo -> ( -> VisitedDateTime datetime -> ); Query OK, 0 rows affected (0.59 sec)Let us now insert date in the table using insert command. The query is as followsmysql> insert into YesterdayDateDemo values(now()); Query OK, 1 row affected (0.15 sec) mysql> insert into YesterdayDateDemo values('2012-12-26 13:24:35'); Query OK, 1 row affected (0.17 sec) mysql> insert into YesterdayDateDemo values('2013-10-22 12:20:32'); Query OK, 1 row affected (0.16 sec)Let ... Read More

980 Views
If you are using Windows Operating System, check your directory my.cnf or my.ini file.mysql> select @@datadir;The following is the output+---------------------------------------------+ | @@datadir | +---------------------------------------------+ | C:\ProgramData\MySQL\MySQL Server 8.0\Data\ | +---------------------------------------------+ 1 row in set (0.00 sec)Reach the above location ‘C:\ProgramData\MySQL\MySQL Server 8.0\Data\”. The screenshot is as follows for my.cnf fileOpen the my.cnf file and write the sql_mode="TRADITIONAL". The syntax is as followssql_mode="TRADITIONAL".After that start your server once again.

4K+ Views
You can create a parameter using IN and OUT. IN is used to take input parameter and OUT can be used for output.The syntax is as followsDELIMITER // CREATE PROCEDURE yourProcedureName(IN yourParameterName dataType, OUT yourParameterName dataType ) BEGIN yourStatement1; yourStatement2; . . N END; // DELIMITER ;First, we will create a table. The query to create a table is as followsmysql> create table SumOfAll -> ( -> Amount int -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. The query ... Read More