dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: SQL join problem

  1. #1
    Join Date
    Jan 2005
    Location
    UK
    Posts
    381

    SQL join problem

    Hi,

    I have this query:

    SELECT * FROM meeting, staff WHERE meeting.meetingid = staff.meetingid AND meeting.meetingid = #meetingid#;

    But it returns multiple values in some cases, when I would like unique values. Would joins solve this or do I need to do seperate querys?

    My sql knowledge is very basic.

    Thankyou

  2. #2
    Join Date
    Mar 2006
    Location
    NCAA Tournament Hell
    Posts
    21
    Try a GROUP BY on those fields that you need to be unique.

  3. #3
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb

    SELECT * FROM meeting left join staff on meeting.meetingid = staff.meetingid WHERE AND meeting.meetingid = #meetingid# group by meeting.meetingid;


    Best Regards
    Adrian

  4. #4
    Join Date
    Jan 2005
    Location
    UK
    Posts
    381
    Hi thanks for your help.

    I get this error when i try to group by:

    Column meeting.title is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

  5. #5
    Join Date
    Jan 2006
    Location
    London
    Posts
    50
    Quote Originally Posted by mattastic
    Hi thanks for your help.

    I get this error when i try to group by:

    Column meeting.title is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    I don't really recognise that message, as long as the column 'title' exists in table 'meeting' you should be ok, even though based on the previous SQL statements, you are not referencing this field directly so it should not matter.

    The only thing I see wrong with this query

    SELECT * FROM meeting left join staff on meeting.meetingid = staff.meetingid WHERE AND meeting.meetingid = #meetingid# group by meeting.meetingid;
    is that 'WHERE AND' is syntactically wrong, and should be either:

    ... WHERE 1 AND ...
    or
    ... WHERE meeting.meetingid = #meetingid# group by meeting.meetingid;
    (lose the AND completly).

  6. #6
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb

    Quote Originally Posted by Brooksie155
    I don't really recognise that message, as long as the column 'title' exists in table 'meeting' you should be ok, even though based on the previous SQL statements, you are not referencing this field directly so it should not matter.

    The only thing I see wrong with this query



    is that 'WHERE AND' is syntactically wrong, and should be either:

    ... WHERE 1 AND ...
    or
    ... WHERE meeting.meetingid = #meetingid# group by meeting.meetingid;
    (lose the AND completly).
    You are right ... I'm wrong

    Regards

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles