SQL
Dnyanesh Sarode
Importing csv to SQL
Right click on table
Table data import wizard
Select the file from Location
Select as a new table
Where Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
Operators
• Comparison Operators:
• Equal to: =
• Not equal to: <>
• Greater than: >
• Less than: <
• Greater than or equal to: >=
• Less than or equal to: <=
• AND: Used to combine multiple conditions, all of which must be
true.
• OR: Used to combine multiple conditions, at least one of which
must be true.
Pattern should be in single quote
Showing Null
Position
Showing Non
Null Values
Aggregate Functions
• SELECT COUNT(column_name) To Check the number of rows,
FROM table_name SELECT count(*) from table_name;
WHERE condition;
• SELECT AVG(column_name)
FROM table_name
WHERE condition;
• SELECT SUM(column_name)
FROM table_name
WHERE condition;
Unique Values
• SELECT DISTINCT column1, column2, ...
FROM table_name;
Delete / Truncate / Drop
• DELETE FROM table_name WHERE condition;
• TRUNCATE TABLE table_name;
• DROP TABLE table_name;
Alter Table
• ALTER TABLE table_name ADD COLUMN column_name data_type;
• ALTER TABLE table_name MODIFY COLUMN column_name
new_data_type;
• ALTER TABLE table_name DROP COLUMN column_name;
Update-set
• UPDATE employees SET salary = 5000, first_name = 'John'
WHERE employee_id = 123;
SET SQL_SAFE_UPDATES = 0;
Limit
• SELECT * FROM table_name LIMIT 5; First 5 Rows
• SELECT * FROM table_name LIMIT 6,1; Skipped 5 Rows then select 2
Thank You
If you have any query, You can ask