Basic queries
Mapping -
Basic form of the SQL SELECT statement.
SELECT
(attribute list)
FROM (table
list)
WHERE
(condition)
Example:
SELECT
collegeID FROM college WHERE collegeID=1;
SELECT
collegeID, collegeName from college where fname='sheryll may';
Aliases
- When you join tables, it's often the case that the tables contain columns
with the same names.
Example:
SELECT E.FNAME, E.LNAME, S.FNAME, S.LNAME
FROM EMPLOYEE AS E, EMPLOYEE AS S
WHERE E.SUPERSSN=S.SSN
FROM EMPLOYEE AS E, EMPLOYEE AS S
WHERE E.SUPERSSN=S.SSN
The use of *
- the * is refer to all the attributes.
Example:
SELECT * FROM college WHERE collegename='CEN';
Distinct
- the distinct is used to not to show the record which have a
duplicate.
Example:
SELECT DISTINCT S.age FROM studentinfo;