Test Index
CBSE Class 12 Computer Science 2025 Paper Set 4
© 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
Table : Artists
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.
| Code | A_Code | Article | DOC | Price |
|---|---|---|---|---|
| PL001 | A0001 | Painting | 2018-10-19 | 20000 |
| SC028 | A0004 | Sculpture | 2021-01-15 | 16000 |
| QL005 | A0003 | Quilling | 2024-04-24 | 3000 |
| A_Code | Name | Phone | DOB | |
|---|---|---|---|---|
| A0001 | Roy | 595923 | r@CrAG.com | 1986-10-12 |
| A0002 | Ghosh | 1122334 | ghosh@CrAG.com | 1972-02-05 |
| A0003 | Gargi | 121212 | Gargi@CrAG.com | 1996-03-22 |
| A0004 | Mustafa | 33333333 | Mf@CrAg.com | 2000-01-01 |
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, ArticlesWHERE Artists.A_Code = Articles.A_CodeAND 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 ArticlesWHERE Article = 'Painting';Result from the records shown (both queries): Roy.
© examsnet.com
Go to Question: