Slip25
Consider the following Entities and Relationships
Politicians (pno, pname, telephone_no)
Party (party_code, party_name)
Relation between Politicians and Party is Many to One.
Constraint: Primary key.
Solution:-
Create a Database in 3NF & write queries for following.
•Display party names in ascending order.
SQL>Select pname from party order by pname asc;
•Find the party who is having less number of members than ‘Congress’ party.
SQL>Select min(party.pname) from politicians,party where politicians.pcode=party.pcode and party.pname <=(select min(party.pname) from politicians,party where politicians.pcode=party.pcode and party.pname=’congress’);
•Display party wise politician name with details.
SQL>Select party.pname,politicians.pname from politicians,party where politicians.pcode=party.pcode order by party.pname,politicians.pname asc;
•Display the party name with the details of politicians whose name include “Rao”.
SQL>Select party.pname,politicians.pname from politicians,party where politicians.pname like ‘%rao%’ and politicians.pcode=party.pcode ;
•Whichparty has maximum politicians
SQL>Select max(party.pname) from politicians,party where politicians.pcode=party.pcode ;
Consider the following Entities and Relationships
Politicians (pno, pname, telephone_no)
Party (party_code, party_name)
Relation between Politicians and Party is Many to One.
Constraint: Primary key.
Solution:-
Create a Database in 3NF & write queries for following.
•Display party names in ascending order.
SQL>Select pname from party order by pname asc;
•Find the party who is having less number of members than ‘Congress’ party.
SQL>Select min(party.pname) from politicians,party where politicians.pcode=party.pcode and party.pname <=(select min(party.pname) from politicians,party where politicians.pcode=party.pcode and party.pname=’congress’);
•Display party wise politician name with details.
SQL>Select party.pname,politicians.pname from politicians,party where politicians.pcode=party.pcode order by party.pname,politicians.pname asc;
•Display the party name with the details of politicians whose name include “Rao”.
SQL>Select party.pname,politicians.pname from politicians,party where politicians.pname like ‘%rao%’ and politicians.pcode=party.pcode ;
•Whichparty has maximum politicians
SQL>Select max(party.pname) from politicians,party where politicians.pcode=party.pcode ;