Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
SQL Interview Questions | Set 2
Next article icon

SQL Interview Questions | Set 2

Last Updated : 21 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
  1. Difference between Locking, Blocking and Deadlocking
    • Locking: Locking occurs when a connection needs access to a piece of data in a database and it locks it for certain use so that no other transaction is able to access it.
    • Blocking: Blocking occurs when a transaction tries to acquire an incompatible lock on a resource that another transaction has already locked. The blocked transaction remains blocked until the blocking transaction releases the lock.
    • Deadlocking: Deadlocking occurs when two or more transactions have a resource locked, and each transaction requests a lock on the resource that another transaction has already locked. Neither of the transactions here can move forward, as each one is waiting for the other to release the lock.
  2. Delete duplicate data from table so that only first data remains constantManagers
    IdNameSalary
    1Harpreet20000
    2Ravi30000
    3Vinay10000
    4Ravi30000
    5Harpreet20000
    6Vinay10000
    7Rajeev40000
    8Vinay10000
    9Ravi30000
    10Sanjay50000
    Query:
    DELETE M1 from managers M1, managers M2 where M2.Name=M1.Name AND M1.Id>M2.Id;
    Output:
    IdNameSalary
    1Harpreet20000
    2Ravi30000
    3Vinay10000
    7Rajeev40000
    10Sanjay50000
  3. Find the Name of Employees where First Name, Second Name, and Last Name is given in the table. Some Name is missing such as First Name, Second Name and maybe Last Name. Here we will use COALESCE() function which will return first Non Null values. Employees
    IDFNameSNameLNameSalary
    1HarpreetSingh30000
    2AshuNULLRana50000
    3NULLVinayThakur40000
    4NULLVinayNULL10000
    5NULLNULLRajveer60000
    6ManjeetSinghNULL60000
    Query :
    SELECT ID, COALESCE(FName, SName, LName) as Name FROM employees;
    Output:
  4. Find the Employees who were hired in the Last n months Finding the Employees who have been hire in the last n months. Here we get desired output by using TIMESTAMPDIFF() mysql function Employees
    IDFNameLNameGenderSalaryHiredate
    1RajveerSinghMale300002017/11/05
    2ManveerSinghMale500002017/11/05
    3AshutoshKumarMale400002017/12/12
    4AnkitaSharmaFemale450002017/12/15
    5VijayKumarMale500002018/01/12
    6DilipYadavMale250002018/02/26
    7JayvijaySinghMale300002018/02/18
    8ReenuKumariFemale400002017/09/19
    9AnkitVermaMale250002018/04/04
    10HarpreetSinghMale500002017/10/10
    Query:
    Select *, TIMESTAMPDIFF(month, Hiredate, current_date()) as 
    DiffMonth from employees
    where TIMESTAMPDIFF(month, Hiredate, current_date()) between
    1 and 5 order by Hiredate desc;
    Note: Here in query 1 and 5 are indicates 1 to n months which show the Employees who have hired last 1 to 5 months. In this query, DiffMonth is an extra column for our understanding which shows the Nth months. Output:
  5. Find the Employees who hired in the Last n daysFinding the Employees who have been hired in the last n days. Here we get desired output by using DATEDIFF() mysql function Employees
    IDFNameLNameGenderSalaryHiredate
    1RajveerSinghMale300002017/11/05
    2ManveerSinghMale500002017/11/05
    3AshutoshKumarMale400002017/12/12
    4AnkitaSharmaFemale450002017/12/15
    5VijayKumarMale500002018/01/12
    6DilipYadavMale250002018/02/26
    7JayvijaySinghMale300002018/02/18
    8ReenuKumariFemale400002017/09/19
    9AnkitVermaMale250002018/04/04
    10HarpreetSinghMale500002017/10/10
    Query:
    select *, DATEDIFF(current_date(), Hiredate)as 
    DiffDay from employees
    where DATEDIFF(current_date(), Hiredate) between
    1 and 100 order by Hiredate desc;
    Note : Here in query 1 and 100 indicates 1 to n days which show the Employees who have hired last 1 to 100 days. In this query DiffDay is an extra column for our understanding which shows the Nth days. Output:
  6. Find the Employees who were hired in the Last n years Finding the Employees who have been hired in the last n years. Here we get desired output by using TIMESTAMPDIFF() MySQL function Employees
    IDFNameLNameGenderSalaryHiredate
    1RajveerSinghMale300002010/11/05
    2ManveerSinghMale500002017/11/05
    3AshutoshKumarMale400002015/12/12
    4AnkitaSharmaFemale450002016/12/15
    5VijayKumarMale500002017/01/12
    6DilipYadavMale250002011/02/26
    7JayvijaySinghMale300002012/02/18
    8ReenuKumariFemale400002013/09/19
    9AnkitVermaMale250002017/04/04
    10HarpreetSinghMale500002017/10/10
    Query:
    select *, TIMESTAMPDIFF(year, Hiredate, current_date()) as 
    DiffYear from employees
    where TIMESTAMPDIFF(year, Hiredate, current_date())
    between 1 and 4 order by Hiredate desc;
    Note: Here in query 1 and 4 are indicates 1 to n years which shows the Employees who have hired last 1 to 4 years. In this query, DiffYear is a extra column for our understanding which show the Nth years. Output:
  7. Select all names that start with a given letter Here we get desired output by using three different queries Employees
    IDFNameLNameGenderSalaryHiredate
    1RajveerSinghMale300002010/11/05
    2ManveerSinghMale500002017/11/05
    3AshutoshKumarMale400002015/12/12
    4AnkitaSharmaFemale450002016/12/15
    5VijayKumarMale500002017/01/12
    6DilipYadavMale250002011/02/26
    7JayvijaySinghMale300002012/02/18
    8ReenuKumariFemale400002013/09/19
    9AnkitVermaMale250002017/04/04
    10HarpreetSinghMale500002017/10/10
    Query:
    select *from employees where Fname like 'A%';

    select *from employees where left(FName, 1)='A';

    select *from employees where substring(FName, 1, 1)='A';
    Note: Here every query will give same output and the list of Employees who's FName start with letter A.

Related articles :

  1. SQL Interview Questions | Set 1
  2. Commonly asked DBMS Questions Set 1
  3. Commonly asked DBMS Questions Set 2

Next Article
SQL Interview Questions | Set 2

D

Delta_Ranger
Improve
Article Tags :
  • Misc
  • SQL
  • Interview Questions
  • Interview-Questions
Practice Tags :
  • Misc

Similar Reads

    SQL Server Interview Questions
    Data is growing every day, and it plays a big part in making important decisions. To manage this data, we need reliable databases, and SQL Server is one of the most popular options out there. Learning SQL Server can lead to exciting careers as an SQL Specialist or SQL Developer. If you’re preparing
    15+ min read
    SQL Interview Questions
    Are you preparing for a SQL interview? SQL is a standard database language used for accessing and manipulating data in databases. It stands for Structured Query Language and was developed by IBM in the 1970's, SQL allows us to create, read, update, and delete data with simple yet effective commands.
    15+ min read
    Spotify SQL Interview Questions
    Spotify is a popular music streaming platform that uses data analysis and management to improve user experience and provide personalized content. Spotify heavily relies on SQL (Structured Query Language) to manage its vast database and derive valuable insights. Whether you're preparing for a job int
    11 min read
    Google SQL Interview Questions
    Google is known for its challenging technical interviews and SQL is a key component of these interviews, especially for roles related to data analysis, database engineering, and backend development. Google SQL interview questions typically focus on candidates' proficiency in writing complex SQL quer
    11 min read
    SQL Query Interview Questions
    SQL or Structured Query Language, is the standard language for managing and manipulating relational databases such as MySQL, Oracle, and PostgreSQL. It serves as a powerful tool for efficiently handling data whether retrieving specific data points, performing complex analysis, or modifying database
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences