SQL - Set 1

SQL Question & Answer Practice

SQL Practice – Questions & Answers

Beginner Level

Q1. What is SQL?

Structured Query Language.

Q2. Select all records.
SELECT * FROM students;
Q3. Select specific columns.
SELECT name FROM students;
Q4. Use WHERE clause.
SELECT * FROM students WHERE age>18;
Q5. Sort records.
SELECT * FROM students ORDER BY name;

Intermediate Level

Q6. Create table.
CREATE TABLE students(
id INT,
name VARCHAR(50)
);
Q7. Insert record.
INSERT INTO students VALUES(1,'Vijay');
Q8. Update record.
UPDATE students SET name='Raj';
Q9. Delete record.
DELETE FROM students WHERE id=1;
Q10. Use DISTINCT.
SELECT DISTINCT city FROM students;

Advanced Level

Q11. Use GROUP BY.
SELECT city,COUNT(*) FROM students GROUP BY city;
Q12. Use HAVING.
HAVING COUNT(*)>1;
Q13. Subquery.
SELECT * FROM students
WHERE age>(SELECT AVG(age) FROM students);
Q14. INNER JOIN.
SELECT * FROM a
INNER JOIN b ON a.id=b.id;
Q15. Create VIEW.
CREATE VIEW v AS SELECT name FROM students;

No comments:

Post a Comment