Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old March 4th, 2004, 10:02 AM
ewebb38 ewebb38 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 40 ewebb38 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 6 m 35 sec
Reputation Power: 5
query help

Hi,

I wasn't sure where to post this exactly, but I'm currently a student trying to learn SQL and need a little help with some queries using Oracle SQL.

1. How do you write a query to display, for example, jobs that are common to department 10, 20, and 30?

2. How you write a query to show a department #, department name, and # of employees that employee less 6 employees and then to display those with the max number of employees?

I know that subqueries have to be performed in order to return the correct results. I would appreciate any tips you might have, and any info that would help me understand this better.

Thank you.

Reply With Quote
  #2  
Old March 4th, 2004, 05:46 PM
thegodfatheruk thegodfatheruk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Manchester
Posts: 5 thegodfatheruk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 15 sec
Reputation Power: 0
Send a message via MSN to thegodfatheruk
Im new(ish) to SQL, but...

for point 1 theres no need to have a subquery, i think it will just read...

Code:
SELECT jobs
FROM table_name
WHERE department IN (10, 20, 30);


For the second i dont really understand what you are asking for?

Hope this helps....students should help students

Reply With Quote
  #3  
Old March 5th, 2004, 12:32 AM
bhurad bhurad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 bhurad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
Hi,
For ur first question try out this:

select job from temp
where job in ( select job from temp where job in
(select job from temp where dept=10)
and dept=20)
and dept=30;


Hope this helps... Good Luck

Reply With Quote
  #4  
Old March 5th, 2004, 08:51 AM
cruelkoder's Avatar
cruelkoder cruelkoder is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 49 cruelkoder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 40 sec
Reputation Power: 5
Quote:
Originally Posted by bhurad
Hi,
For ur first question try out this:

select job from temp
where job in ( select job from temp where job in
(select job from temp where dept=10)
and dept=20)
and dept=30;


Hope this helps... Good Luck


Dude whats that query, i dont understand at all

Reply With Quote
  #5  
Old March 5th, 2004, 01:54 PM
ewebb38 ewebb38 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 40 ewebb38 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 6 m 35 sec
Reputation Power: 5
Quote:
Originally Posted by thegodfatheruk
Im new(ish) to SQL, but...

for point 1 theres no need to have a subquery, i think it will just read...

Code:
SELECT jobs
FROM table_name
WHERE department IN (10, 20, 30);


For the second i dont really understand what you are asking for?

Hope this helps....students should help students


Thanks for the tip, however, that query doesn't return what I'm looking for. The query above gives me a list of all the job names in Departments 10, 20, and 30. I need to run a query that returns the common job names out of all those departments.

Reply With Quote
  #6  
Old March 8th, 2004, 05:03 AM
bhurad bhurad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 bhurad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
Quote:Dude whats that query, i dont understand at all

Hi,

Consider a table temp with a structure:
dept number,
job varchar2(25)

We're in need of job common to the depts 10,20 & 30.

The innermost query:
select job from temp where dept=10
-returns all the jobs in dept 10.

The next query:
select job from temp where job in
(select job from temp where dept=10)
and dept=20
-returns only those jobs that are found in dept 20 also.

The final returns those jobs that are found in dept 30 also.Thus we arrive at the result set.
I'm new to SQL so there might be some other easy way also.Not sure about it.This query worked in my system.Would like to know whether it is correct???

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > query help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway