SQL Queries Class 12
SQL Queries Class 12
1) Create database
2) Show databases
3) Use database
4) Create Table
5) Describe table
9) Show table
Multiple columns
can also be
selected
11) Show the information of any particular on the basis of given information
#TYPES OF JOINS
1) INNER JOIN:
This inner join will match rows from both info and employees
tables where the roll_no in the info table matches the id in the
employees table. (fields may vary in this case which is roll no. and id)
2) RIGHT JOIN
This right join will return all rows from the employees table, along
with matching rows from the info table based on the condition.
If there are no matches in the info table, it will return NULL
values for the columns of the info table.
3) LEFT JOIN :
This left join will return all rows from the info table, along with
matching rows from the employees table based on the
condition. If there are no matches in the employees table, it
will return NULL values for the columns of the employees
table.
4) CROSS JOIN:
This cross join will return the Cartesian product of both tables,
resulting in all possible combinations of rows from the info table
with rows from the employees table. It does not require any
condition to be specified.
OUTPUT:
QUESTIONS
Q1. State two advantages of using Databases.
Q14. Consider the following tables DRESS and MATERIAL. Write SQL
commands for the statements
(i) To display DCODE and DESCRIPTION of each dress in ascending order of DCODE.
(ii) To display the details of all the dresses which have LAUNCHDATE in between 05–DEC–
07 and 20–JUN–08 (inclusive of both the dates).
(iii) To display the average PRICE of all the dresses which are made up of material with
MCODE as M003.
(IV) To display material wise highest and lowest price of dresses from DRESS table. (Display
MCODE of each dress along with highest and lowest price)
(v) SELECT SUM (PRICE) FROM DRESS WHERE MCODE=‘M001’;
(vi) SELECT DESCRIPTION, TYPE FROM DRESS, MATERIAL WHERE DRESS.
DCODE=MATERIAL. MCODE AND DRESS. PRICE>=1250.
(vii) SELECT MAX(MCODE) FROM MATERIAL.
(viii) SELECT COUNT(DISTINCT PRICE) FROM DRESS
MCQ
10. What does the SQL query `SELECT * FROM table WHERE column LIKE
'A%'` do?
a) Selects all records where the column starts with 'A'
b) Selects all records where the column contains 'A'
c) Selects all records where the column ends with 'A'
d) Selects all records where the column exactly matches 'A'
13. Which of the following integrity constraints ensures that all values in a
column are distinct?
a) UNIQUE b) CHECK c) PRIMARY KEY d) FOREIGN
KEY
14. In a relational database, what does the term "Cardinality" refer to?
a) The number of records in a table b) The number of columns in a
table
c) The number of distinct values in a column
d) The number of unique combinations of values in a table
16. Which SQL statement is used to delete a column from an existing table?
a) DELETE COLUMN b) DROP COLUMN c) REMOVE COLUMN d)
ALTER TABLE
18. Which SQL function is used to find the minimum value in a column?
a) MIN() b) MAX() c) SUM() d) COUNT()
19. What is the output of the SQL query `SELECT COUNT(*) FROM table`?
a) The total number of records in the table
b) The average value of all records in the table
c) The sum of all values in the table
d) The number of distinct values in the table
21. In SQL, which of the following statements correctly retrieves the average
value of a column named "sales" from a table named "transactions" only for
the year 2023?
a) SELECT AVG(sales) FROM transactions WHERE YEAR(date) = 2023;
b) SELECT AVG(sales) FROM transactions GROUP BY YEAR(date)
HAVING YEAR(date) = 2023;
c) SELECT AVG(sales) FROM transactions WHERE date BETWEEN '2023-
01-01' AND '2023-12-31';
d) SELECT AVG(sales) FROM transactions WHERE date LIKE '%2023%';
22. What does the SQL statement `SELECT DISTINCT column1, column2
FROM table;` do?
a) Selects all unique combinations of values from column1 and column2 in
the table
b) Selects only the distinct values from column1 and column2 in the table
c) Selects all records from the table, displaying only distinct values in
column1 and column2
d) Selects only the distinct values from either column1 or column2 in the
table
23. Which of the following statements about the SQL GROUP BY clause is
correct?
a) The GROUP BY clause can only be used with aggregate functions.
b) The GROUP BY clause sorts the results in ascending order by default.
c) The columns listed in the GROUP BY clause must also appear in the
SELECT clause.
d) The GROUP BY clause can be used to filter rows based on a condition.
24. In SQL, what does the expression `SELECT * FROM table1 INNER JOIN
table2 ON table1.column = table2.column;` accomplish?
a) Retrieves all records from table1 and table2 where the values in the
specified columns match.
b) Retrieves all records from table1 and table2, combining them into a single
result set.
c) Retrieves only the records from table1 that have matching records in
table2 based on the specified column.
d) Retrieves all records from table1 and table2, including non-matching
records, and displays them side by side.
25. What does the SQL statement `SELECT TOP 5 * FROM table ORDER BY
column DESC;` do?
a) Retrieves the top 5 records from the table and orders them by the
specified column in descending order.
b) Retrieves all records from the table and displays only the top 5 unique
values for the specified column.
c) Retrieves the bottom 5 records from the table and orders them by the
specified column in descending order.
d) Retrieves the top 5 records from the table and orders them by the
specified column in ascending order.