Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Consider the tables PRODUCT and BRAND given below:

Question 34 CBSE Sample Question Paper 2024 Boards - Teachoo.PNG

Write SQL queries for the following:

(i) Display product name and brand name from the tables PRODUCT and BRAND.

Answer

Answer by student

SELECT PName, BName

FROM PRODUCT, BRAND

WHERE PRODUCT.BID = BRAND.BID;

Detailed answer by teachoo

  • The question asks us to display product name and brand name from the tables PRODUCT and BRAND. These are two different tables that have a common column called BID, which stands for brand ID. This column can be used to join the two tables and fetch the relevant data.
  • To display product name and brand name from the tables PRODUCT and BRAND, we need to use the SELECT statement in SQL. The SELECT statement is used to query data from one or more tables in a database.
  • The syntax of the SELECT statement is:

SELECT column1, column2, ...

FROM table1, table2, ...

WHERE condition;

  • The SELECT clause specifies the columns to be displayed in the result. The FROM clause specifies the tables to be queried. The WHERE clause specifies the condition to filter the rows that match the criteria.
  • In this case, we want to display the PName column from the PRODUCT table and the BName column from the BRAND table. We also want to query both the PRODUCT and BRAND tables. We need to use a condition that matches the BID column from both tables, so that we can get the correct product name and brand name for each product.
  • The SQL query for this question is:

SELECT PName, BName -- Select the columns PName and BName

FROM PRODUCT, BRAND -- Query both the PRODUCT and BRAND tables

WHERE PRODUCT.BID = BRAND.BID; -- Use a condition that matches the BID column from both tables

  • This query will display the product name and brand name for each product in the database. For example, one of the rows in the result will be:

PName

BName

Shampoo

Medimix

So, this is how we can write an SQL query to display product name and brand name from the tables PRODUCT and BRAND.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo