Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
picking off unique entries
Old 02-26-2009, 05:58 PM picking off unique entries
Junior Talker

Posts: 1
Name: Ellie
Trades: 0
Hi,

I wouldn't normally post without looking through the forum for similar questions but I really don't know how to formulate this in a search. So, please if you can and you find time, help me.

I am trying to pick out graduated students within a certain calendar year. It's a rather long query, involves some joins on different tables and I have the following problem:

I have a table of all graduated students within the last say 10 years. Every student has a unique id as primary key and there are students that have graduated with more than one degree from this institution. Every degree receives a (global) sequence number. I need to pick the students with only one degree for this term, i.e. student A could have graduated with a both BA and a BS in the calendar year in question. They would then be marked number 1 (BA) and number 2 (BS) and I only need number 1. So technically, I could do a search by sequence = 1 and be done with it. The problem arises when student B graduated with his 1st degree a couple of years back and is in my graduate population now with a degree marked 2nd that I need to pick it up. The sequence number then becomes useless.

My question is, is it possible to while selecting multiple rows to do a comparison between the retrieved results and pick up the one with the minimum sequence number? My first thought was to group by and then use having min(seq no) (or something) but SQL developer doesn't let me do this at the end of the query:

select distinct a.id, .........., a.seq_no, .....
from .... a
inner join ... b
on a.id = b.id
left join .... c
on a.id = c.id
where .... and ..... and .... and ....
order by a.id;

when i remove the order by and try to do a group by, SQL developer complains

Any Ideas?
Thank you,
Ellie
P.S. Database is Banner (is for higher education, runs on top of Oracle 10g)
P.P.S. There's no write privileges, i.e. can't create a table and run subsequent queries on it must be done in one sitting. Am I asking for something impossible?
d-dee is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-27-2009, 08:13 PM Re: picking off unique entries
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
I don't know Oracle but perhaps something like:
Code:
SELECT column FROM table GROUP BY column HAVING ( COUNT(column) = 1 )
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 03-29-2009, 01:00 PM Re: picking off unique entries
Novice Talker

Posts: 13
Name: mark
Location: Oxford, England
Trades: 0
Hi. The following should work (if you are picking off the one record with minimum sequence value); it does assume that sub-queries are working ok.

Quote:
select * from maintable
where seq_id in
(select min(seq_id)
from degreetable
group by studentid)
This code has the advantage that it will select those students (or perhaps I should say graduates) that have just the one entry.

Edit: I misread your post. You're after those students with just one degree? The above code will select all students with at least 1 degree (and choose the record with the lowest sequence). Change the code slightly and we have a solution:

Quote:
select * from maintable
where studentid in
(select studentid
from degreetable
group by studentid having count(*) = 1)

Last edited by DBMark; 03-29-2009 at 01:09 PM.. Reason: Misread opening post
DBMark is offline
Reply With Quote
View Public Profile Visit DBMark's homepage!
 
Reply     « Reply to picking off unique entries
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26463 seconds with 12 queries