Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How Select Statement Work

Posted on 2006-07-04
9
Medium Priority
?
1,091 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 48

Expert Comment

by:schwertner
ID: 17036648
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
ID: 17040231
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 48

Expert Comment

by:schwertner
ID: 17040414
SELECT sal
FROM salary
WHERe rownum = 2
ORDER BY sal;
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 48

Accepted Solution

by:
schwertner earned 80 total points
ID: 17040420
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
ID: 17041069
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
ID: 17041226
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
ID: 17130315
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
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.
Via a live example, show how to take different types of Oracle backups using RMAN.

604 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