Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Need help with this query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-04, 15:33
kicker22 kicker22 is offline
Registered User
 
Join Date: Apr 2004
Location: Michigan
Posts: 44
Need help with this query

I really need help with this,
this is the scenario, i am trying to list all students with SID, lname, fname, year term, program name

Now here is the trick part, students can go to the same program more than one year..so when I run the query, it will list for me the student twice..

Now I want to create a query that wont list the student twice who attended the same program twice. AND I still want it to list student twice or more if he attended different program or so..
so yeah, what is the keyword in the query that will let me only select the students who went abroad with no year and programname match!

thanks,
hope to hear from you guys soon..

morad
Reply With Quote
  #2 (permalink)  
Old 06-22-04, 16:11
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,573
DISTINCT

-PatP
Reply With Quote
  #3 (permalink)  
Old 06-22-04, 17:25
kicker22 kicker22 is offline
Registered User
 
Join Date: Apr 2004
Location: Michigan
Posts: 44
Wink hmm

Well, I tried distinct before, and distinct only works when all fields match.
but then all fields match except the term.

For example.

ID, SID, Name, Program_Name, Term
01, 123, Ray , CEA, , 2004
02, 123, Ray , CEA, , 2005


Now when I run distinct, it will show both of them because term.value is different!

so is there a way to run a query that will not list both of the records if the program_name are the same.?


Let me purify what I want

Problem 1:
ID, SID, Name, Program_Name, Term
01, 123, Ray , CEA, , 2004
02, 123, Ray , CEA, , 2005

Result wanted when run query:
ID, SID, Name, Program_Name, Term
02, 123, Ray , CEA, , 2005
*it would show the most recent term record and not both of them, because program name match!

Problem 2:
ID, SID, Name, Program_Name, Term
01, 123, Ray , CEA, , 2004
02, 123, Ray , IIS, , 2005

Result wanted when run a query:
ID, SID, Name, Program_Name, Term
01, 123, Ray , CEA, , 2004
02, 123, Ray , IIS, , 2005
*It would show both records because program name dont match.


You are my life saver pat

thanks
Reply With Quote
  #4 (permalink)  
Old 06-22-04, 18:11
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,573
Let's try this one out to see how it flies... It might not be exactly what you want, but I'll bet it is at least pretty close!
Code:
SELECT Max(a.id), a.SID, a.Name, a.Program_name, Max(a.Year) FROM myTable AS a GROUP BY a.SID, a.Name, a.Program_name
-PatP
Reply With Quote
  #5 (permalink)  
Old 06-22-04, 19:39
kicker22 kicker22 is offline
Registered User
 
Join Date: Apr 2004
Location: Michigan
Posts: 44
la la la

it worked.

thanks

p.s. I learned a lot from you..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On