473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

standard sql query

16 New Member
Hello Everybody,
I face a problem to
SELECT the paticular customer record from 50 records in database whose salary is 15 th heighest with out using 'limit' keyword in mysql or 'rownum' in oracle.
query should be in standard SQL ,which will run in all oracle,mysql,and in sql server also.
please try.................
Oct 30 '07 #1
5 1460
amitpatel66
2,367 Recognized Expert Top Contributor
Hello Everybody,
I face a problem to
SELECT the paticular customer record from 50 records in database whose salary is 15 th heighest with out using 'limit' keyword in mysql or 'rownum' in oracle.
query should be in standard SQL ,which will run in all oracle,mysql,and in sql server also.
please try.................
Please post what you have tried for my reference!!
Oct 31 '07 #2
samit
16 New Member
Please post what you have tried for my reference!!

I have tried the following queries
the following query runs in mysql to treat name of the employee of 30 th heighest salary.
SELECT name FROM SALARY_TABLE ORDER BY SALARY DESC LIMIT 29,1
the following query runs in oracle to treat name of the employee of 30 th heighest salary.
SELECT ROWNUM, name FROM SALARY_TABLE ORDER BY SALARY DESC where ROWNUM=30;

But I like to write a common query to run in both. I face this question in some interview table
Nov 1 '07 #3
amitpatel66
2,367 Recognized Expert Top Contributor
I have tried the following queries
the following query runs in mysql to treat name of the employee of 30 th heighest salary.
SELECT name FROM SALARY_TABLE ORDER BY SALARY DESC LIMIT 29,1
the following query runs in oracle to treat name of the employee of 30 th heighest salary.
SELECT ROWNUM, name FROM SALARY_TABLE ORDER BY SALARY DESC where ROWNUM=30;

But I like to write a common query to run in both. I face this question in some interview table
try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT ename,g.msal FROM (select MIN(salary) msal from emp e where 30 > (SELECT count(*) from emp where salary > e.salary)) g,emp d
  3. WHERE d.salary = g.msal
  4.  
  5.  
The above query will give you the enames of all the employees whose salary is 30th highest.

It will return all names if two employees have same salary at 30th position!!
Nov 1 '07 #4
samit
16 New Member
try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT ename,g.msal FROM (select MIN(salary) msal from emp e where 30 > (SELECT count(*) from emp where salary > e.salary)) g,emp d
  3. WHERE d.salary = g.msal
  4.  
  5.  
The above query will give you the enames of all the employees whose salary is 30th highest.

It will return all names if two employees have same salary at 30th position!!
*************************reply******************** ********************
thanks a lot for sending this query. this is running fine
Nov 2 '07 #5
amitpatel66
2,367 Recognized Expert Top Contributor
*************************reply******************** ********************
thanks a lot for sending this query. this is running fine
You are Welcome :)

Regards,
Amit
Nov 2 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

13
3470
by: Maroon | last post by:
Hi, I want to write a standard java user defined function, like this example:- select db_fun("roll"), roll from student; **db_fun() will work for all tables of the all databse here db_fun is...
5
16446
by: Dani | last post by:
Hi, I´m no superuser when it comes to MS Access. So I use MS Query to pull out info from an SQL database to Excel. I have a tabel containing different "titles" or "colums". One contains a date....
2
8600
by: Papegoja | last post by:
Hi, A week ago I had a question how to get MS Query to return a standard date to a "YEAR-MONTH" (YYYY-MM) format. I received a great answer from Jerry Boone!!! It follows: SELECT...
6
2678
by: Sam Lazarus | last post by:
I need to import data from a website, but the text is arranged badly: Name:John Doe Title:Grunt ID:314159 Name:Jane Doe Title:Queen-Bee ID:271828 etc...
7
2157
by: Tim Donaldson | last post by:
Hi, I wonder if anyone has some ideas on the best way to create this type of query. I have a table of four columns. The first column field is called "year" and contains years from 1980 to...
5
3306
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
2
1277
by: allyn44 | last post by:
Hello, I am trying to figure out how to create a sdev field on a report or in a query that is based on a claculation of 2 fields. I have these fields: Number of samples--this is a...
23
14002
by: Nishant Saini | last post by:
Dear All, We have a database which contains many tables which have millions of records. When We attach the database with MS SQL Server 2005 Standard Edition Server and run some queries (having...
2
1908
by: martin | last post by:
Hello, Today I fetched the standard Access-2003 template "orders management db" from http://office.microsoft.com/en-au/templates/TC010185481033.aspx?pid=CT101426031033 In de openingform one...
4
1356
by: Twanne | last post by:
Hi, I'd like to use a standard value in a field. This value should be the lowest value of a table minus 1. The query I wrote for this works and looks like this: SELECT Min(dkey) AS dkeylock...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.