basic sql query interview questions code example

Example 1: sql interview questions

/* Answer to: "sql interview questions" */

/*
  Here are 50 common questions you may be asked in an interview!
  Go to https://www.guru99.com/sql-interview-questions-answers.html
  for the answers of each question.
  
  1. What is DBMS?
  2. What is RDBMS?
  3. What is SQL?
  4. What is a Database?
  5. What are tables and Fields?
  6. What is a primary key?
  7. What is a unique key?
  8. What is a foreign key?
  9. What is a join?
  10. What are the types of join and explain each?
  11. What is normalization?
  12. What is Denormalization.
  13. What are all the different normalizations?
  14. What is a View?
  15. What is an Index?
  16. What are all the different types of indexes?
  17. What is a Cursor?
  18. What is a relationship and what are they?
  19. What is a query?
  20. What is subquery?
  21. What are the types of subquery?
  22. What is a stored procedure?
  23. What is a trigger?
  24. What is the difference between DELETE and TRUNCATE commands?
  25. What are local and global variables and their differences?
  26. What is a constraint?
  27. What is data Integrity?
  28. What is Auto Increment?
  29. What is the difference between Cluster and Non-Cluster Index?
  30. What is Datawarehouse?
  31. What is Self-Join?
  32. What is Cross-Join?
  33. What is user defined functions?
  34. What are all types of user defined functions?
  35. What is collation?
  36. What are all different types of collation sensitivity?
  37. Advantages and Disadvantages of Stored Procedure?
  38. What is Online Transaction Processing (OLTP)?
  39. What is CLAUSE?
  40. What is recursive stored procedure?
  41. What is Union, minus and Interact commands?
  42. What is an ALIAS command?
  43. What is the difference between TRUNCATE and DROP statements?
  44. What are aggregate and scalar functions?
  45. How can you create an empty table from an existing table?
  46. How to fetch common records from two tables?
  47. How to fetch alternate records from a table?
  48. How to select unique records from a table?
  49. What is the command used to fetch first 5 characters of the string?
  50. Which operator is used in query for pattern matching?
*/

Example 2: sql interview questions

/*SQL query to fetch duplicate records from a table .
Ans. In order to find duplicate records from the table, we can use GROUP BY on all the fields and then use the HAVING clause to return only those fields whose count is greater than 1 i.e. the rows having duplicate records.
*/ 
SELECT FullName, ManagerId, DateOfJoining, City, COUNT(*) FROM EmployeeDetails GROUP BY FullName, ManagerId, DateOfJoining, City HAVING COUNT(*) > 1;

Tags:

Sql Example