Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 10th, 2006, 8:32 PM   #1
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
SQL select distinct

Say I'm trying to select some records from table "info" where "x > 5" and "y < 5" and z is distinct in the results. so i would get at most ONE record that meets the condition for each z. I tried
SELECT DISTINCT x,y,z 
FROM info WHERE x > 5 AND y < 5
but that will return distinct combinations of x,y, and z not just distinct z's. Any ideas?
OpenLoop is offline   Reply With Quote
Old Apr 10th, 2006, 9:19 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I think it's just a matter of how you used (placed) the token, DISTINCT. You can achieve the same results with:

SELECT x, y, z
FROM info
WHERE x > 5 AND y < 5
GROUP BY z

(assuming I read your intentions correctly, there's a DISTINCT possibility I didn't)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 10th, 2006, 9:30 PM   #3
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
After 20+ tries i got it. Thanks.
OpenLoop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC