Test Index

CBSE Class 12 Computer Science 2025 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 34 of 37
Marks: +1, -0
Assume that you are working in the IT Department of a Creative Art Gallery (CAG), which sells different forms of art creations like Paintings, Sculptures etc. The data of Art Creations and Artists are kept in tables Articles and Artists respectively. Following are few records from these two tables :
Table : Articles
CodeA_CodeArticleDOCPrice
PL001A0001Painting2018-10-1920000
SC028A0004Sculpture2021-01-1516000
QL005A0003Quilling2024-04-243000
Table : Artists
A_CodeNamePhoneEmailDOB
A0001Roy595923r@CrAG.com1986-10-12
A0002Ghosh1122334ghosh@CrAG.com1972-02-05
A0003Gargi121212Gargi@CrAG.com1996-03-22
A0004Mustafa33333333Mf@CrAg.com2000-01-01
Note :
• The tables contain many more records than shown here.
• DOC is Date of Creation of an Article.
As an employee of CAG, you are required to write the SQL queries for the following :
(i) To display all the records from the Articles table in descending order of price.
(ii) To display the details of Articles which were created in the year 2020.
(iii) To display the structure of Artists table.
(iv) (a) To display the name of all artists whose Article is Painting through Equi Join.
OR
(b) To display the name of all Artists whose Article is 'Painting' through Natural Join.
Solution:  
(i) ORDER BY … DESC sorts from the highest price to the lowest.
SELECT * FROM Articles ORDER BY Price DESC;
(ii) The YEAR() function takes the year out of a date.
SELECT * FROM Articles WHERE YEAR(DOC) = 2020;
(or WHERE DOC BETWEEN '2020-01-01' AND '2020-12-31'; none of the rows shown is from 2020, but the table has more records)
(iii) DESCRIBE (short form DESC) shows the columns, their data types and keys.
DESCRIBE Artists;
(iv)(a) An equi join joins the two tables with an equality condition on the common column, written in the WHERE clause.
SELECT Name FROM Artists, Articles
WHERE Artists.A_Code = Articles.A_Code
AND Article = 'Painting';
OR (b) A natural join matches the columns with the same name (A_Code) by itself, so no join condition is written.
SELECT Name FROM Artists NATURAL JOIN Articles
WHERE Article = 'Painting';
Result from the records shown (both queries): Roy.
© examsnet.com
Advertisements
Go to Question: