What is MYSQL?
ANS:- MySQL is an open-source relational database management system (RDBMS) that is widely used for managing and manipulating data. It is based on SQL(Structured Query Language) for accessing and managing records.

What is SQL?
ANS:- SQL Stands for Structured Query Language which provides a way to interact with the database to perform operations to work on data.
example:- Create data, Retrieve data, Update data, Deletion of data (CRUD).

What is a Database?
ANS:- A database is a structured and organized collection of tables, rows, and columns that are stored in the computer system.
The database is designed to efficiently store, manage, and retrieve data for various purposes, such as data analysis, information management, and application development.

What is RDBMS?
ANS:- RDBMS stands for Relational Database Management System. RDBMS is based on the relational model of data. The relational model organizes data into structured tables with rows and columns, where each row represents a record and each column represents an attribute or field of that record.

Difference Between MySQL and SQL:-

What is the Difference Between SQL and MySQL - Pediaa.Com

Explain About Keys in MYSQL:-
ANS:- IN MYSQL, relational database management systems (RDBMS), keys are used to establish relationships between tables, ensure data integrity, and optimize query performance.

  1. Primary Key:-
    A primary key is a column (or a combination of columns) that uniquely identifies each row in a table.
    Syntax Query:- CREATE TABLE <table_name> ( <column_name> <DATATYPE> PRIMARY KEY, -- Other columns);
  2. Candidate key:-
    A candidate key is a minimal super key, meaning it is the smallest set of columns that can uniquely identify rows in a table. Candidate keys can be chosen as primary keys.
  3. Super Key:-
    A super key is a set of one or more columns that can be used to uniquely identify rows in a table. It may contain more columns than the minimum required to identify rows (which would be a candidate key).
  4. Composite Key:-
    A composite key consists of two or more columns used together as a key to uniquely identify rows in a table.
  5. Foreign Key:-
    A foreign key is used to create a relationship between two tables. It ensures referential integrity by linking data in one table to data in another.
    The foreign key in one table refers to the primary key in another table.
    Syntax:-

What is DDL?
ANS:- DDL stands for Data Definition Language, DDL is used for defining and Managing the structure of a database
DDL is used for creating a database, modifying a database, and deleting database objects like tables, values, and indexes.
In DDL Following commands are used:-
Create, Alter, Drop, Truncate

Write a query to create a Database?
Ans:-
SYNTAX:-  CREATE DATABASE [IF NOT EXISTS]<database_name>;
Example:- CREATE DATABASE [IF NOT EXISTS] employees;

Write a query to Delete a Database?
Ans:-
SYNTAX:-  DROP DATABASE <database_name>;
Example:- DROP DATABASE employees;

Write a query to Create a Table?
Ans:-
SYNTAX:-  CREATE TABLE [IF NOT EXISTS] <table_Name> ( col_name1 datatype, col_name2 datatype, col_name3 datatype)
Example:- CREATE TABLE [IF NOT EXISTS] empDetails ( emp_id INT, name VARCHAR(100), description TEXT);

Write a query to Delete a Table?
Ans:-
SYNTAX:-  DROP TABLE <table_name>;
Example:- DROP TABLE empDetails;

What is Truncate in MYSQL?
ANS:- 'TRUNCATE' is used to remove all rows from a table.

Write a query to delete all data inside the table?
Ans:-
SYNTAX:-  TRUNCATE TABLE <table_name>;
Example:- TRUNCATE TABLE empDetails;

What are Alter Commands?
ANS:- ALTER Commands are used to modify the structure of an existing database, table. Example:- modify the name of the database, tables

Write a query to add a new column in an existing table?
Ans:-
SYNTAX:-  ALTER TABLE <table_name> ADD <column_name> data_type;
Example:- ALTER TABLE employees ADD email VARCHAR(100);

Write a query to modify the column or rename the column?
ANS:-
SYNTAX:- ALTER TABLE table_name CHANGE <old_column_name> <new_column_name> <new_data_type> [new_constraints];

Write a query to delete the column?
Ans:-
SYNTAX:-  ALTER TABLE <table_name> DROP COLUMN column_name;
Example:- ALTER TABLE employees DROP COLUMN email;

Difference Between Delete and Truncate:-

What is the difference between DELETE and TRUNCATE statements? – MSBI  Developer

What is a Constraints?
ANS:- Constraint is a rule or condition that is applied to the data in a database table to ensure data integrity and consistency. Constraints help enforce the accuracy and reliability of data by specifying limits or conditions that data must meet.

What is Auto Increment?
ANS:- "Auto-increment" is a property used in relational database management systems (RDBMS) to automatically generate unique integer values for a column when new rows are inserted into a table.
syntax:- CREATE TABLE <table_name> ( <col_name> INT AUTO_INCREMENT PRIMARY KEY, < -- Other columns>);

What is DML?
ANS:- DML stands for Data Manipulation Language. DML is used for interacting with and manipulating data stored in a relational database.

Write a query to insert data in a table?
Ans:-
SYNTAX:-  INSERT INTO <table_name>(col_name1,col_name2) VALUES (col_value1, col_value2);
Example:- INSERT INTO employees(E_id,e_name) VALUES (201,"David");

Write a query to insert multiple records in a table?
Ans:-
SYNTAX:-  INSERT INTO <table_name>(col_name1,col_name2) VALUES (col_value1, col_value2),(col_value1, col_value2),(col_value1, col_value2),(col_value1, col_value2),...;
Example:- INSERT INTO employees(E_id,e_name) VALUES (201, "David"), (202, "Oliver"), (202, "William"), (204, "Sophia"),...;

What is DQL?
ANS:- DQL stands for Data Query Language. DQL specifically deals with querying and retrieving data from a relational database. DQL is primarily focused on the SELECT statement.

Write a query to display the starting 10 records of the table?
Ans:-
SYNTAX:-  SELECT * FROM <table_name> LIMIT 5 ;
Example:- SELECT * FROM employees LIMIT 5;

What is the Where clause?
ANS:- Where Clause is used to filter rows in a result set based on specified conditions.
EXAMPLE:-  SELECT * FROM <table_name> WHERE condition;

Write a query to display the data of employees where the department name is 'HR'?
Ans:-
SYNTAX:-  SELECT * FROM <table_name> WHERE condition;
Example:- SELECT * FROM employee WHERE department = 'HR';

Write a query to display the data of employees whose salary is greater than 60000?
Ans:-
SYNTAX:-  SELECT * FROM <table_name> WHERE condition;
Example:- SELECT * FROM employee WHERE salary > 60000;

Write a query to display the average salary of each department?
Ans:-
SYNTAX:-  SELECT avg(),<col_lists> FROM <table_name> GROUP BY <col_name> ;
Example:- SELECT department, avg(salary), FROM employees GROUP BY Department;

Write a query to update the city of an employee where the employee id is 3?
Ans:-
SYNTAX:- UPDATE <table_name> SET <col_name> = 'value' WHERE condition;
Example:- UPDATE employees SET city = 'DELHI' WHERE employeeID = 3;

Write a query to display the data of employees in ascending order on the basis of employee name?
Ans:-
SYNTAX:-  SELECT * FROM <table_name> ORDER BY <col_name> [ASC | DESC];
Example:- SELECT * FROM employees ORDER BY empName ASC;

Write a query to Count the number of employees in the employees' table in each city?
Ans:-
SYNTAX:-  SELECT count(),<col_name> FROM <table_name> GROUP BY <col_name> ;
Example:- SELECT count(employee_name), city FROM employees GROUP BY city;

Write a query to display the top 5 highest-paid employees in the employees' table?
Ans:-
SYNTAX:-  SELECT <col_lists> FROM <table_name> order by <col_name> [ASC | DESC ] LIMIT 5;
Example:- SELECT EmployeeID, FirstName, LastName, Salary FROM Employees ORDER BY Salary DESC LIMIT 5;

Write a query to display the 2nd highest-paid employee in the employees' table?
Ans:-
SYNTAX:-  SELECT <col_lists> FROM <table_name> order by <col_name> [ASC | DESC ] LIMIT 1 OFFSET 1;
Example:- SELECT EmployeeID, FirstName, LastName, Salary FROM Employees ORDER BY Salary DESC LIMIT 1 OFFSET 1;

Write a query to display the Nth highest-paid employee in the employees' table?
Ans:-
SYNTAX:-  SELECT <col_lists> FROM <table_name> order by <col_name> [ASC | DESC ] LIMIT 1 OFFSET Nth-1;
Example:- SELECT EmployeeID, FirstName, LastName, Salary FROM Employees ORDER BY Salary DESC LIMIT 1 OFFSET Nth-1;

Write a query to display the lowest-paid employee in the employees' table?
Ans:-
SYNTAX:-  SELECT <col_lists> FROM <table_name> order by <col_name> [ASC | DESC ] LIMIT 5;
Example:- SELECT EmployeeID, FirstName, LastName, Salary FROM Employees ORDER BY Salary ASC LIMIT 1;

Write a query to calculate the difference between the Highest and Lowest Salaries?
Ans:-
SYNTAX:-  SELECT MAX(<col_name>) , MIN(<col_name>),(MAX(<col_name>) - MIN(<col_name>)) FROM <table_name> ;

Example:- SELECT MAX(salary) , MIN(salary),(MAX(salary) - MIN(salary)) as salaryDiff FROM <table_name> ;

What is Joins?
ANS:- Join is an SQL operation performed to combine rows from two or more tables based on a related column between them. Joins are fundamental for querying data from multiple tables in a database.

TYPES OF JOINS:-

  1. Inner Join:-
    ANS:- An INNER JOIN retrieves rows from both tables that have matching values in the specified columns.
    Syntax:- SELECT <table1.col_list>,<table2.col_list> FROM table1 INNER JOIN table2 ON <condition>;
  2. Left Join:-
    ANS:- A LEFT JOIN returns all rows from the left table and the matched rows from the right table. If there is no match, NULL values are returned for columns from the right table.
    Syntax:- SELECT <table1.col_list>,<table2.col_list> FROM table1 LEFT JOIN table2 ON <condition>;
  3. Right Join:-
    ANS:- A RIGHT JOIN is similar to a LEFT JOIN, but it returns all rows from the right table and the matched rows from the left table. If there is no match, NULL values are returned for columns from the left table.
    Syntax:- SELECT <table1.col_list>,<table2.col_list> FROM table1 RIGHT JOIN table2 ON <condition>;
  4. Cross Join:-
    ANS:- A CROSS JOIN produces the Cartesian product of the two tables involved, meaning it combines every row from the first table with every row from the second table.
    Syntax:- SELECT <table1.col_list>,<table2.col_list> FROM table1 CROSS JOIN table2 ;

What is the use of Like Operator?
ANS:- The LIKE operator in SQL is used to perform pattern matching on text data. It is primarily used in the WHERE clause of a SELECT statement to filter rows based on a specified pattern.
SYNTAX:- SELECT * FROM <table_name> WHERE LIKE 'pattern';

Write a query to display all employees whose names start with 'A'?
ANS:-
SYNTAX:- SELECT <col_lists> FROM <table_name> WHERE <col_name> LIKE 'Pattern';
EXAMPLE:- SELECT employee_name FROM employees WHERE employee_name LIKE 'A%';

Write a query to display all employees whose names end with 'L'?
ANS:-
SYNTAX:- SELECT <col_lists> FROM <table_name> WHERE <col_name> LIKE 'Pattern';
EXAMPLE:- SELECT employee_name FROM employees WHERE employee_name LIKE '%L';

Write a query to display all employees whose names are like ' n'?
ANS:-
SYNTAX:- SELECT <col_lists> FROM <table_name> WHERE <col_name> LIKE 'Pattern';
EXAMPLE:- SELECT employee_name FROM employees WHERE employee_name LIKE '%L';