Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

Re: FN-FORUM: SQL SELECT DISTINCT with INNER JOIN

date posted 4th September 2007 15:52

DISTINCT is like uniq in Unix - it will remove only exactly duplicate
rows in the returned tuples.

Seeing as you have both tblCourses.ID and tblCourseListings.ID returned,
you will get the unique pairings of both these values.

I do not see how you can have a unique tblCourses.ID if it appears in
more than one CourseListing (category) - unless you do not retreive the
category...

What you can do with DISTINCT and GROUP BY is say count the number of
categories a give course is in.

Sorry if I have missunderstood your table structure.

Regards

Gidon

Paul Cooper wrote:
> Hi
>
> I'm adding a search function to a site that searches through the
> titles of courses in my table tblCourses. However also have a table
> called tblCourseListings so that courses can belong to more than one
> category. So my structure is this:
>
> tblCourses
> - ID
> - Title
>
> tblCourseListings
> - ID
> - CourseID
>
>
> My search works OK using …
>
> strSQL1 = "SELECT tblCourses.Title AS Title, tblCourses.ID,
> tblCourses.Description AS Description, tblCourses.Active,
> tblCourseListings.CourseID, tblCourseListings.ID AS CourseListingID
> FROM tblCourses INNER JOIN tblCourseListings ON tblCourses.ID =
> tblCourseListings.CourseID WHERE … etc.
>
> Except that if a match is found it will list the course in every
> category it belongs to. I've read about SELECT DISTINCT on this page
> …
>
> http://www.w3schools.com/sql/sql_select.asp
>
> … but I think because I have a join it's not so simple. Basically I
> want tblCourses.ID to be unique. I've tried …
>
> strSQL1 = "SELECT DISTINCT tblCourses.ID, tblCourses.Title AS Title,
> tblCourses.Description AS Description … etc.
>
> … but it makes no difference. Any help is appreciated.
>
> TIA
> Paul
>
>



Messages by Day
September 30th 2007
September 29th 2007
September 28th 2007
September 27th 2007
September 26th 2007
September 25th 2007
September 24th 2007
September 23rd 2007
September 22nd 2007
September 21st 2007
September 20th 2007
September 19th 2007
September 18th 2007
September 17th 2007
September 16th 2007
September 15th 2007
September 14th 2007
September 13th 2007
September 12th 2007
September 11th 2007
September 10th 2007
September 9th 2007
September 8th 2007
September 7th 2007
September 6th 2007
September 5th 2007
September 4th 2007
September 3rd 2007
September 2nd 2007
September 1st 2007


Messages by Month
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007


Messages by Year
2009
2008
2007
2006
2005
2004
2003
2002
2001
2000