Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT query, as well as distinct? 1

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I have the following query:

SELECT DISTINCT(glinks_ClickTrack.LinkID) FROM glinks_ClickTrack
JOIN glinks_Links ON glinks_ClickTrack.LinkID = glinks_Links.ID
WHERE ClickType = "Hits"
ORDER BY glinks_ClickTrack.Created LIMIT 5;

What I need to do, is also get the values from the glinks_Links table. I tried:

SELECT glinks_Links.*,DISTINCT(glinks_ClickTrack.LinkID) FROM glinks_ClickTrack
JOIN glinks_Links ON glinks_ClickTrack.LinkID = glinks_Links.ID
WHERE ClickType = "Hits"
ORDER BY glinks_ClickTrack.Created LIMIT 5;

...but that didn't work.

Is there a way to achieve what I'm trying to do?

TIA!

Andy
 
please note: DISTINCT is not a function
Code:
SELECT DISTINCT
       glinks_Links.*
  FROM glinks_ClickTrack
INNER
  JOIN glinks_Links 
    ON glinks_Links.ID = glinks_ClickTrack.LinkID
 WHERE glinks_ClickTrack.ClickType = 'Hits'
ORDER 
    BY glinks_ClickTrack.Created LIMIT 5;

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Thanks, seems to work like a charm :)

I think I need to look up on the "INNER" function - as looks like it does quite a bit.

Star coming your way for your help - thanks again!

Andy
 
in INNER JOIN, the keyword INNER is optional, and in LEFT OUTER JOIN, the keyword OUTER is optional

i always write them both out anyway

:)

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Thanks - may actually get your MySQL book at some point, as could do with learning up on all these more advanced features <G>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top