SQL - Set 3

SQL Question & Answer Practice

SQL Practice – Questions & Answers

Beginner Level

Q31. AND operator.
WHERE age>18 AND city='Delhi';
Q32. OR operator.
WHERE city='Delhi' OR city='Mumbai';
Q33. NOT operator.
WHERE NOT city='Delhi';
Q34. NULL check.
WHERE city IS NULL;
Q35. IS NOT NULL.
WHERE city IS NOT NULL;

Intermediate Level

Q36. LEFT JOIN.
SELECT * FROM a LEFT JOIN b ON a.id=b.id;
Q37. RIGHT JOIN.
SELECT * FROM a RIGHT JOIN b ON a.id=b.id;
Q38. UNION.
SELECT name FROM a UNION SELECT name FROM b;
Q39. UNION ALL.
UNION ALL
Q40. DROP table.
DROP TABLE students;

Advanced Level

Q41. EXISTS.
WHERE EXISTS(SELECT 1 FROM marks);
Q42. Find duplicates.
SELECT name,COUNT(*) FROM students
GROUP BY name HAVING COUNT(*)>1;
Q43. Delete duplicates.
DELETE FROM students
WHERE id NOT IN (SELECT MIN(id) FROM students GROUP BY name);
Q44. TRANSACTION.
BEGIN; COMMIT;
Q45. ROLLBACK.
ROLLBACK;

No comments:

Post a Comment