Lab Lect 2
Lab Lect 2
Lab Lect 2
Lecture:2
Instructor: Nitesh Jha
The SQL SELECT Statement
SELECT Syntax
It will select display all the records in two columns from the table.
SQL WHERE Clause
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that fulfill a
specified condition.
WHERE Syntax
SELECT *
FROM Product
WHERE category='Gadgets'
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
• DELETE
– The Delete query is used to delete records from a table.
– Syntax:
• DELETE FROM TABLE_NAME
WHERE CONDITION_LIST ;
• WHERE condition is optional
• If WHERE condition is not specified, all rows from
specified table will be deleted
• It will only delete records from the table, Table
structure will already be there.
9
Modifying the Structure of table (DDL
Commands)
Alter table allows changing the structure of an existing table (like add, delete or modify
columns data_types ). SEE BELOW SYNTAX
ADD NEW COLUMN-
ALTER TABLE TABLENAME
ADD NEWCOLUMN1 DATA_TYPE SIZE,
NEWCOLUMN2 DATA_TYPE SIZE,
….
NEW_COLUMN N DATA_TYPE SIZE;
ORDER BY Syntax
Query:
Display the name of of instructor who belongs to Physics
department and getting salary less than 9000.
Example
f. SELECT DISTINCT DEPT_NAME FROM
DEPARTMENT;
SQL CONDITION STATEMENT
CHECK AN ATTRIBUTE VALUE IS
WITHIN RANGE
Example
SELECT * FROM INSTRUCTOR
WHERE SALARY BETWEEN 60000 AND
80000;
SQL CONDITION STATEMENT
MATCHING STRING PATTERN
Two types of matching
• Full string matching: It uses '%'
Ex: 'P%' matches 'Peter', 'Pam', 'Pratima'
'%i%' matches 'Srinivasan', 'Einstein', 'El Said'
• One letter matching: It uses „_‟
Ex: '_ohit' matches 'Mohit', 'Rohit', 'Sohit'
QUERY: Display details about Instructors with names starting
from K.
SELECT * FROM INSTRUCTOR WHERE NAME LIKE
'K%';
SQL CONDITION STATEMENT