Database Reference
In-Depth Information
Sol: SELECT Student_ID, Name, Semester , MarksObt , Maxmarks FROM Student, Stu-
dent_result WHERE Student. Student_ID = Student_result. Student_ID; Example: Select
Student_ID, Name, Semester , MarksObt and Maxmarks from Student, Student_result table
where MarksObt are more than 600.
Sol: SELECT Student_ID, Name, Semester , MarksObt , Maxmarks FROM Student, Stu-
dent_result
WHERE Student. Student_ID = Student_result. Student_ID
AND Student_result. MarksObt > 600;
Using Table Aliases
An alias is an alternative name for a field,table or value. Aliases are assigned with the AS
keyword.
Example:
SELECT Customer_name, Customer_address
FROM Customer C, Order O
WHERE C. Customer_id = O. Customer_id
Cross-Join
A cross-join merges all data from all tables into a single result set regardless of
matching column names or their values.
Example:
SELECT COUNT(*) FROM Student;
SELECT COUNT(*) FROM Staff;
SELECT COUNT(*) FROM
(SELECT St.Name, S.fname FROM Student St, Staff Sf); If Student table has 20 rows and
Staff table has 10rows.
The cross-join has 200 (20 * 10) rows.
Self Join
Referring the same table more than once in a single SELECT statement is called
self join
Example:
SELECT Cr1. Customer_id, Cr1. Customer_name, Cr1.cust_contact FROM Customer
Cr1, Customer Cr2
WHERE Cr1. Customer_name = Cr2. Customer_name AND Cr2. Customer _contact = '
Vikas';
Combined Queries
SQL queries can be combined using the UNION operator. Results multiple SELECT
Search WWH ::




Custom Search