0% found this document useful (0 votes)
30 views10 pages

Lab 3

The document discusses SQL JOIN and SUBQUERY operations. It provides examples of using subqueries to find cities and countries that meet certain population and GNP criteria. It also gives examples of JOIN queries to retrieve related data from multiple tables based on shared countrycodes.

Uploaded by

Ratha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views10 pages

Lab 3

The document discusses SQL JOIN and SUBQUERY operations. It provides examples of using subqueries to find cities and countries that meet certain population and GNP criteria. It also gives examples of JOIN queries to retrieve related data from multiple tables based on shared countrycodes.

Uploaded by

Ratha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SQL

JOIN and SUBQUERY


Subquery
• Display city name, district and population from table city where population is
greater than Kelang’s population and country code is MYS. (Note: Assume that
Kelang population is not known)

SELECT name, district, population


FROM city
WHERE countrycode = 'MYS' and population >
(SELECT population
FROM city
WHERE countrycode = 'MYS' and name = 'Kelang');
Subquery - Output
Subquery
• Display country name and GNP for all countries that have GNP
greater than Australia’s GNP. (Note: GNP Australia is unknown)

SELECT name, GNP


FROM country
WHERE GNP >
(SELECT GNP
FROM country
WHERE name = 'Australia');
Subquery - output
Join
• Display countrycode, country name, language, isofficial and
percentage from table Country and Countrylanguage where
Countrycode = MYS

SELECT CL.countrycode, C.Name, language, Isofficial, percentage


FROM Countrylanguage CL, Country C
WHERE CL.countrycode = C.code AND countrycode = 'MYS';
Join - output
Join

• Display city ID, city name, district, country name, and


population from tables City and Country where
countrycode is MYS.

SELECT CT.ID, CT.name, CT.district, C.name, CT.population


FROM City CT, Country C
WHERE CT.countrycode = C.code and Countrycode = 'MYS';
Join - output
END

You might also like