SQL Queries Interview Questions and Answers - Query Examples

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

2/3/2014 SQL Queries Interview Questions and Answers - Query Examples

Skip to content
Jump to main navigation and login
Jump to additional information

Nav view search


Navigation

Home
Careers Jobs
Interview Questions
Placement Test
Seminar Topics
B.E Projects
Tutorials
Blog
Forum

Search

Top 80 + SQL Query Interview Questions and Answers with Examples


Top 80 + SQL Query Interview Questions and Answers with Examples 200 Votes
( 200 Votes )

User Rating: 4 / 5

Please rate Vote 5 Rate

Details
Created: Tuesday, 26 February 2013 02:54
Last Updated: Friday, 20 December 2013 08:42
Hits: 95700

1
2
3
4
5
6
7
All Pages

Page 1 of 7

Frequently asked basic and advanced Top 80 + SQL Queries Interview Questions and Answers with Examples for Freshers and Experienced Java, PHP, .Net Developers and
DBA in Oracle, MySQL and SQL Server 2008 Database.

For Interview Questions on Advanced SQL Queries go to Page 5 and Page 6 of this article. For detailed
SQL Server Monitoring explanation of SQL functions visit SQL Tutorials.

www.dbainabox.com If the answers are same for Oracle, MySQL and SQL databases, only one query is specified. If the SQL Commands
differ for Oracle, MySQL and SQL Server, specific queries with respect to a database is provided.
Monitor, Alert, and Diagnose. Just $269
monitors all your sql servers Interview Questions on SQL are based on following two tables, Employee Table and Employee Incentive Table.

Table Name : Employee

EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY JOINING_DATE DEPARTMENT


1 John Abraham 1000000 01-JAN-13 12.00.00 AM Banking
2 Michael Clarke 800000 01-JAN-13 12.00.00 AM Insurance
3 Roy Thomas 700000 01-FEB-13 12.00.00 AM Banking
4 Tom Jose 600000 01-FEB-13 12.00.00 AM Insurance
5 Jerry Pinto 650000 01-FEB-13 12.00.00 AM Insurance
6 Philip Mathew 750000 01-JAN-13 12.00.00 AM Services
7 TestName1 123 650000 01-JAN-13 12.00.00 AM Services
8 TestName2 Lname% 600000 01-FEB-13 12.00.00 AM Insurance

Table Name : Incentives

EMPLOYEE_REF_ID INCENTIVE_DATE INCENTIVE_AMOUNT


1 01-FEB-13 5000
2 01-FEB-13 3000
3 01-FEB-13 4000
1 01-JAN-13 4500
2 01-JAN-13 3500

SQL Queries Interview Questions and Answers on "SQL Select" - Examples


1. Get all employee details from the employee table

Select * from employee

2. Get First_Name,Last_Name from employee table

Select first_name, Last_Name from employee

3. Get First_Name from employee table using alias name “Employee Name”

Select first_name Employee Name from employee

4. Get First_Name from employee table in upper case

Select upper(FIRST_NAME) from EMPLOYEE

5. Get First_Name from employee table in lower case

Select lower(FIRST_NAME) from EMPLOYEE

6. Get unique DEPARTMENT from employee table

select distinct DEPARTMENT from EMPLOYEE

7. Select first 3 characters of FIRST_NAME from EMPLOYEE

Oracle Equivalent of SQL Server SUBSTRING is SUBSTR, Query : select substr(FIRST_NAME,0,3) from employee

http://a4academics.com/interview-questions/397-top-100-database-sql-interview-questions-and-answers-examples-queries 1/2
2/3/2014 SQL Queries Interview Questions and Answers - Query Examples
Oracle Equivalent of SQL Server SUBSTRING is SUBSTR, Query : select substr(FIRST_NAME,0,3) from employee

SQL Server Equivalent of Oracle SUBSTR is SUBSTRING, Query : select substring(FIRST_NAME,0,3) from employee

MySQL Server Equivalent of Oracle SUBSTR is SUBSTRING. In MySQL start position is 1, Query : select substring(FIRST_NAME,1,3) from employee

8. Get position of 'o' in name 'John' from employee table

Oracle Equivalent of SQL Server CHARINDEX is INSTR, Query : Select instr(FIRST_NAME,'o') from employee where first_name = 'John'

SQL Server Equivalent of Oracle INSTR is CHARINDEX, Query: Select CHARINDEX('o',FIRST_NAME,0) from employee where first_name = 'John'

MySQL Server Equivalent of Oracle INSTR is LOCATE, Query: Select LOCATE('o',FIRST_NAME) from employee where first_name = 'John'

9. Get FIRST_NAME from employee table after removing white spaces from right side

select RTRIM(FIRST_NAME) from employee

10. Get FIRST_NAME from employee table after removing white spaces from left side

select LTRIM(FIRST_NAME) from employee

11. Get length of FIRST_NAME from employee table

Oracle,MYSQL Equivalent of SQL Server Len is Length , Query :select length(FIRST_NAME) from employee

SQL Server Equivalent of Oracle,MYSQL Length is Len, Query :select len(FIRST_NAME) from employee

12. Get First_Name from employee table after replacing 'o' with '$'

select REPLACE(FIRST_NAME,'o','$') from employee

13. Get First_Name and Last_Name as single column from employee table separated by a '_'

Oracle Equivalent of MySQL concat is '||', Query : Select FIRST_NAME|| '_' ||LAST_NAME from EMPLOYEE

SQL Server Equivalent of MySQL concat is '+', Query : Select FIRST_NAME + '_' +LAST_NAME from EMPLOYEE

MySQL Equivalent of Oracle '||' is concat, Query : Select concat(FIRST_NAME,'_',LAST_NAME) from EMPLOYEE

14. Get FIRST_NAME ,Joining year,Joining Month and Joining Date from employee table

SQL Queries in Oracle, Select FIRST_NAME, to_char(joining_date,'YYYY') JoinYear , to_char(joining_date,'Mon'), to_char(joining_date,'dd') from EMPLOYEE

SQL Queries in SQL Server, select SUBSTRING (convert(varchar,joining_date,103),7,4) , SUBSTRING (convert(varchar,joining_date,100),1,3) , SUBSTRING (convert(varchar,joining_date,100),5,2) from EMPLOYEE

SQL Queries in MySQL, select year(joining_date),month(joining_date), DAY(joining_date) from EMPLOYEE

Prev
Next >>

Export SharePoint to SQL


www.axioworks.com/SQList
Live export of SharePoint lists to normalised SQL Server tables
Close info

Additional information

► SQL Database
► Access Database Tutorial
► SQL Server Tool

Featured Posts

Careers Choices for Electronics and Communication Engineers | Job Opportunities

Careers Guidance for Computer Science Engineers | Job Opportunities

SQL Interview Questions and Answers for Freshers, Experienced | Database

Top 80 + SQL Query Interview Questions and Answers with Examples

Realted Articles

RDBMS Definition, DBMS Definition and SQL Advantages


SQL Interview Questions and Answers for Freshers, Experienced | Database
Java OOPS Interview Questions and Answers
C++ Interview Questions and Answers For Freshers | Experienced
.Net Framework Interview Questions and Answers
ADO.Net Interview Questions and Answers for Freshers, Experienced
Oracle Interview Questions and Answers on SQL Queries and Database Theory
Core Java Interview Questions and Answers
Java Inheritance Example Code - Extends

You are here: Home Interview Questions Database and SQL Interview Questions and Answers Top 80 + SQL Query Interview Questions and Answers with Examples

http://a4academics.com/interview-questions/397-top-100-database-sql-interview-questions-and-answers-examples-queries 2/2

You might also like