Solved

How Select Statement Work

Posted on 2006-07-04
9
1,082 Views
Last Modified: 2013-12-11
Hi experts,,

Can any one help me to understand the mechanism of select statement or how to start thinking of solving a select statement.. for example how to think of a select statement that brings the second heights salary in the company ... really i need to understand how select statement works please i need help here


Thanx

0
Comment
Question by:loay
9 Comments
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
You have to think using SETS.
Imagine a table as set of rows and columns.
You can select SUBSET of rows and/or columns.
You can join set from one table with set from other table using different techniques - joins, Union, Minus set operations.
0
 

Author Comment

by:loay
Comment Utility
Thanks ,,but I want the internal mechanism of select as I mentioned earlier for example how to start thinking of a select statement to bring the second largest salary in a company .. To solve such selects you need to understand what is going on inside the select itself

0
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
SELECT sal
FROM salary
WHERe rownum = 2
ORDER BY sal;
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 47

Accepted Solution

by:
schwertner earned 20 total points
Comment Utility
No, you do not need to know what happens behind the scene.
Only some rules.

sal is the salary column
salary is the table that contains salaries
rownum is pseudocolumn that ordered the result set
order by means sort values of the column sal

In fact I did an error:

SELECT sal
FROM salary
WHERe rownum = 2
ORDER BY sal DESC;


DESC means descending.
0
 

Author Comment

by:loay
Comment Utility
thanx experts u r really great people but its not the query what i want i want to understand how select works because it will help me understand alot of things like explain plane and all the behind scien happend there
0
 
LVL 4

Expert Comment

by:sudhi022299
Comment Utility
You need to really stop worrying about the internals and start concentrating on writing queries. The best thing to start is the HR schema that comes with oracle. Once you feel that you can write queries, then as mentioned above, start thinking in terms of *sets*.

0
 
LVL 1

Expert Comment

by:Tareq_Asebie
Comment Utility
there is many function used in SQL statement  like :

aggregate function
 1- sum
 2- count
 3- max
 4- min
 5- avg

string function
 1- lower
 2- upper
 3- substr
 4- instr

you will write like this statement  

 select  max(sal) from emp
   where sal <>(select max(sal) from emp)

change the name of column as the same name in your table




0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now