# Select. select Att 1, Att 2, Att 3,…, Att n from Tablename where (condition) Order by att1,att2 |desc; //Order By (Ascending & Descending) Explanation:

## Presentation on theme: "Select. select Att 1, Att 2, Att 3,…, Att n from Tablename where (condition) Order by att1,att2 |desc; //Order By (Ascending & Descending) Explanation:"— Presentation transcript:

select

select Att 1, Att 2, Att 3,…, Att n from Tablename where (condition) Order by att1,att2 |desc; //Order By (Ascending & Descending) Explanation: –condition will determine the row(s) which will be retrieved from the table. –If you want to select all the attributes from a table you can use all (*) operator.

Logical Operators NOT –Negation of the condition AND –The two conditions must be satisfied OR –The 1 st, the 2 nd or both of them must be satisfied

Logical Operation >, >=, between lowervalue and uppervalue –attribute/condition value lays in the closed interval [lowervalue,uppervalue] in (v 1,v 2,v 3, …, v n ) –attribute/condition value must match one value in the arches Like

select example select * from college; select Cid, Cname from college; select * from college where cid=10; select Cid, Cname from college where cid between 10 and 30; select Cid, Cname from college where cid in (10,30);

select from more than one table select T1.Att1, T1.Att2, T2.Att1,T2.Att2 from table1 T1, table2 T2 where (condition); Explanation: –Condition will determine which rows in the table1 related with table2

select example select T1.sid,T1.Sname, T2.cname from students T1, college T2 where T1.cid = T2.cid;

View benefits Create or replace view Std_view as select T1.sid,T1.Sname, T2.cname from students T1, college T2 where T1.cid = T2.cid;

Select from dual Select 1+3, sysdate from dual;

Alias Name Select att1 as “col-alias”, att2 as “col-alias”, att3 as “col-alias” From TableName Where (conditon) Order by att1 | col-alias; Notes: –As is optional. – “ ” bounded the column alias name is optional if your column alias name has no space, or special characters. –if the letter case is important.

Alias Name Select sid as “StudentID”, Sname “Student Name” From students Where sid >=20 Order by “StudentID”; --------------------------------------------------------------------- Note: –Use can use the alias name with the “order by” phrase. –You can’t use the alias name with the “where” phrase.

Aggregation Functions The aggregation function return number value and ignore the null values. –Count(att_name) –Sum(att_name) –Max(att_name) –Min(att_name) –Avg(att_name)

example Select count(saverage),sum(saverage), sum(saverage)/count(saverage), avg(saverage) from students; ------------------------ Select college.cid,cname, avg(saverage) from students,college where students.cid=college.cid group by college.cid,cname;

Select From Where Group by Having Order by

Select college.cid,cname, avg(saverage) from students,college where students.cid=college.cid group by college.cid,cname having avg(saverage)> 80;

select * from students where cid = (select cid from students where sid=12345);

Similar presentations