0% found this document useful (0 votes)
81 views5 pages

database/sql Tutorial/6 Select Query

The document discusses using select queries in SQL including aggregate functions, selecting records from multiple tables, using where clauses with conditions like greater than, between, in, like, order by, and grouping with functions. It provides examples of SQL queries for each technique discussed and indicates they will be questions on an exam.

Uploaded by

sagarbolisetti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views5 pages

database/sql Tutorial/6 Select Query

The document discusses using select queries in SQL including aggregate functions, selecting records from multiple tables, using where clauses with conditions like greater than, between, in, like, order by, and grouping with functions. It provides examples of SQL queries for each technique discussed and indicates they will be questions on an exam.

Uploaded by

sagarbolisetti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Select Query (/database/sql-tutorial/6-select-query)

Page 2 of 3

1. Using Aggregate functions: Count,Min,Max,Sum,Avg.


a. Find the number of rows in emp ?
1

SELECT count(*) FROM emp;

b. Find the how many different Job profile are there in Employee table ?
1

SELECT COUNT(DISTINCT job) FROM emp;

c. Find out how many people were given commision ? ( Count function does n't include null as
it counts)
1

SELECT COUNT(comm)FROM emp;

d.
e.
f.

Q5:Select records from two tables;


5.1
1

SELECT e.ename, d.deptno,e.sal FROM emp e,dept d;

5.2 Select records from two tables depending condition suppose where deptno of from both emp and dept
mathes
1

?
Select e.ename, d.deptno,e.sal from emp e,dept d where e.deptno=d.deptn
o;

Q6: Select records using where clause;


6.1
1

SELECT ename,sal FROM emp WHERE sal>2000

6.2 Select records from emp and dept where both deptno matches
1

SELECT e.ename,e.sal,d.deptno FROM emp e,dept d WHERE e.deptno=d.deptno?

6.3 Select secords where empno=1003


1

SELECT * FROM emp WHERE empno=1003

6.4 Select records where ename is KING


1

SELECT * FROM emp WHERE ename='KING';

Q7:Select records using or;


7.1
1

SELECT ename,sal FROM emp WHERE deptno=10 OR deptno= 20

SELECT * FROM emp WHERE city='LONDON' OR city='PARIS'

SELECT * FROM emp WHERE sal>2000 OR comm IS NOT NULL

7.2
1
7.3
1

Q8: Select records using between and;


8.1
1

SELECT * FROM emp WHERE sal BETWEEN 2000 AND 3000

SELECT * FROM dept WHERE deptno BETWEEN 20 AND 40;

SELECT * FROM emp WHERE empno BETWEEN 1001 TO 1010;

8.2
1
8.3
1

Q9: Select records using in;


9.1
1

SELECT * FROM emp WHERE ename IN('SCOTT','WARD','ALLEN')

SELECT ename FROM emp WHERE sal IN(1000,2000.3000.3200,3300);

9.2
1

Q10: Select records using not in;


1

SELECT * FROM emp WHERE ename NOT IN('SCOTT','WARD','ALLEN')

Q11: Select records using null;


1

SELECT * FROM emp WHERE comm IS NULL;

Q12:Select records using not null;


1

SELECT * FROM emp WHERE comm IS NOT NULL;

Q13:Select records using like;


13.1
1

SELECT * FROM emp WHERE ename LIKE'S%';

SELECT * FROM emp WHERE ename LIKE 'sC___';

SELECT * FROM emp WHERE ename LIKE 'AL%';

SELECT * FROM emp WHERE ename LIKE 'A_L_N';

SELECT * FROM emp WHERE ename LIKE '___L%';

13.2
1
13.3
1
13.4
1
13.5
1

Q14:Select records using not like;


1

SELECT * FROM emp WHERE ename NOT LIKE 'A%';

Q15:Select records using multiple conditions.


15.1
1

SELECT * FROM emp WHERE comm IS NOT NULL AND sal >2000 AND deptno>20;

SELECT * FROM emp WHERE sal>2000 AND deptno>20 AND ename NOT LIKE(A%)

15.2
1
15.3
1

?
SELECT * FROM emp WHERE deptno<20 AND comm IS NOT NULL OR sal IN{1000,20
00,300

Q16:Select records using function;


16.1
1

SELECT ename,sum(sal+comm) AS total FROM emp

1
2

SELECT count(*) FROM emp;


16.3

SELECT deptno,avg(sal) AS avgsal FROM emp GROUP BY deptno;

16.2

Q17:Select records using order by;


17.1
1

SELECT * FROM emp ORDER BY sal

SELECT ename,sal FROM emp ORDER BY sal,ename

SELECT empno,ename,sal FROM emp ORDER BY sal DESC,empno,empname

17.2
1
17.3
1

Pages:

1 (/database/sql-tutorial/6-select-query?limit=1&limitstart=0)

3 (/database/sql-tutorial/6-select-query?limit=1&start=2)

Prev (/database/sql-tutorial/7-complex-queries-in-sql)

Most Read Articles


Computer Awareness Home (/quiz/computerawareness)
Complex Queries in SQL ( Oracle )
(/database/sql-tutorial/7-complex-queries-in-sql)
Struts2 Interview Questions and Answers
(/java/struts2/interview-questions)
Quiz Home (/quiz)
Java Programming Interview Questions
(/java/core-java/33-interview-questions)

You might also like