• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login

Cart

SQL Query Interview Questions

  • January 23, 2020
  • CODE OF GEEKS
  • 1


In this post, we are going to look at various SQL queries that are frequently asked in various interviews across various companies.

Also See : DBMS INTERVIEW QUESTIONS

Q. Write a SQL Query to display all records from a table.

A. Select * from table_name;

Q. Write a SQL Query to display all records of employee whose name starts with ‘S’.

A. Select * from employee where emp_name like ‘S%’;

Q. Write a SQL query for printing the employee name from EMP table for alternate rows.

A. Even rows :

Select emp_id from (Select rowno, emp_Id from EMP) where mod(rowno,2)=0;

Odd rows :

Select emp_id from (Select rowno, emp_Id from EMP) where mod(rowno,2)=1;

Q. Write a SQL Query for printing the unique records from the table EMP.

A. Select distinct emp_id, emp_name from EMP;

Q. Write a SQL Query to display the employee id whose first name is ‘Vishal’ and second name is ‘Roy’.

A. Select emp_id from EMP where fir_name=’Vishal’ AND last_name=’Roy’;

Q. Write a SQL Query to fetch “emp_name” from EMP table In Upper Case.

A. Select upper(emp_name) from EMP;

Q. Write a SQL Query to print the first four characters of  emp_name from EMP table.

A. Select substring(emp_name,1,4) from EMP;

Q. Write a SQL query that fetches the unique values of DEPARTMENT from EMP table and prints its length.

A. Select distinct length(DEPARTMENT) from EMP;

Q. Write a SQL Query to print Employee id details from the EMP table order by emp_name in ascending order.

A. Select emp_id from EMP order by emp_name asc;

Q. Write an SQL Query to print all Employee details whose emp_name ends with ‘a’ and contains six alphabets.

A. Select * from EMP where emp_name like ‘_____a’;



Q. Write an SQL Query to print all Employee details whose emp_salary lies between 10,000 and 1,00,000.

A. Select * from EMP where emp_salary between 10,000 and 1,00,000;

Q. Write a SQL Query to print details of the EMP who have joined in Mar’2018.

A. Select * from EMP where year(join_date) = 2018 and month(join_date) = 3;

Q. Write a SQL Query to fetch common records of two tables.

A. Select * from Table1 INTERSECT Select * from Table2;

Q. Write a SQL Query to display the top 5 records of a table.

A. Select TOP 5 * from EMP order by emp_salary DESC;

Q. Write a SQL Query to show the last record from a table.

A. Select * from EMP where emp_id = (Select max(emp_id) from EMP);

Q. Write a SQL Query to fetch the names of Employee who have highest salary.

A. Select emp_name, emp_salary from EMP WHERE emp_salary = (Select max(emp_salary) from EMP);

Q. Write a SQL Query to find 2nd highest salary of an employee.

A. Select max(emp_salary) from EMP where emp_salary IN (SELECT emp_salary from EMP MINUS SELECT max(emp_salary) from EMP);

Q. Write a SQL Query to find 3rd highest salary of an employee.

A. Select emp_salary from EMP order by emp_salary desc limit 2,1;

In the above query, offset is set to two.

Q. Write a SQL Query to display the all rows(non-repeating) in two tables.

A. Select emp_name from EMP1 UNION SELECT emp_name from EMP2;

Q. Write a SQL Query to sort the employee’s lastname descending by their last name.

A. Select * from EMP order by emp_lastname DESC;

Q. Write a SQL Query to find the customers that have an OrderPrice value higher than the average OrderPrice value.

A. Select Customer from Orders where OrderPrice>(Select AVG(OrderPrice) from Orders);

Also See : DBMS INTERVIEW QUESTIONS



  • Previous Operators in Python
  • Next 100 Most Asked Java Interview Questions

1 comment on “SQL Query Interview Questions”

  1. Priti Gaikwad says:
    September 30, 2020 at 7:08 pm

    Thank you for this valuable Interview Questions

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

return Statement in Python with Example
  • November 27, 2021
assert Statement in Python with Example
  • November 27, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →