If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Can't Use Distinct here!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-05, 09:53
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
Exclamation Can't Use Distinct here!

Hi All!!!
I'd Like to know how can I select one only row for each reference... I will post here the SQL clause
Note that I am working on Access

SELECT Badges.BadgeReference, Visitors.VisitorName, EventVisitors.VisitorCheckOutDate, EventVisitors.Event, EventVisitors.VisitorBadge, Visitors.VisitorState
FROM (Visitors INNER JOIN Badges ON Visitors.VisitorReference = Badges.BadgeReference) INNER JOIN EventVisitors ON (Visitors.Visitor_ID = EventVisitors.Visitor) AND (Badges.Badge_ID = EventVisitors.VisitorBadge)
WHERE (((Badges.BadgeReference) Is Not Null) AND ((EventVisitors.VisitorCheckOutDate) Is Not Null) AND ((Visitors.VisitorState)=0))
ORDER BY EventVisitors.VisitorCheckOutDate DESC;

It returns to me all the time the badge was out in each event... I want it to show the last event that each BadgeReference was retrieved...

Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 01-27-05, 11:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
SELECT Badges.BadgeReference
     , Visitors.VisitorName
     , EV.VisitorCheckOutDate
     , EV.Event
     , EV.VisitorBadge
     , Visitors.VisitorState
  FROM (
       Visitors 
INNER 
  JOIN Badges 
    ON Visitors.VisitorReference 
     = Badges.BadgeReference
       ) 
INNER 
  JOIN EventVisitors as EV
    ON Visitors.Visitor_ID = EV.Visitor
   AND Badges.Badge_ID = EV.VisitorBadge
 WHERE Badges.BadgeReference Is Not Null
   AND EV.VisitorCheckOutDate 
     = ( select max(VisitorCheckOutDate)
           from EventVisitors
          where VisitorBadge = EV.VisitorBadge )
   AND Visitors.VisitorState = 0
ORDER 
    BY EV.VisitorCheckOutDate DESC
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-27-05, 12:00
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
Thank you very very very very and a lots of many manys Much!!!!!

You have saved my day.... You sure are pretty good at this

See ya

Keep up that good work that you do
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

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