Thursday, May 12, 2011

SQL Statement - SELECT

Select data from 1 table
SELECT * FROM TableNames

Select data from 2 or more tables
SELECT table1.*, table2.* FROM table1,table2 WHERE table1.field1=table2.field1

Append 2 tables
SELECT * FROM table1
UNION
SELECT * FROM table2

Select data which is not exists in another table
SELECT * FROM table1 WHERE NOT EXISTS (SELECT * FROM table2 WHERE table1.field1=table2.field1)

No comments: