SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    INNER JOIN goes crazy

    Hello,

    I have table with articles

    Articles:
    -----------
    ID | Name | category_id

    and other table with article attributes:

    Attributes:
    -------------
    ID | Attribute | article_id

    Result:

    What i need is to select all articles WHERE category_id='5' AND Attribute='1024x768'

    Can anyone please help me with this?! Thank you!!

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this

    Code MySQL:
    SELECT art.id FROM articles art
    LEFT JOIN attributes attr on attr.article_id = art.id
    WHERE art.category_id='5' AND attr.Attribute='1024x768'

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,276
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by iDeaStuff View Post
    What i need is to select all articles WHERE category_id='5' AND Attribute='1024x768'
    Code:
    SELECT articles.ID
         , articles.Name
      FROM articles 
    INNER 
      JOIN attributes 
        ON attributes.article_id = articles.ID
       AND attributes.Attribute = '1024x768'
     WHERE articles.category_id = 5
    philip, your LEFT OUTER JOIN will behave exactly like an inner join because you have a non-NULL condition in the WHERE clause
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Code:
    SELECT articles.ID
         , articles.Name
      FROM articles 
    INNER 
      JOIN attributes 
        ON attributes.article_id = articles.ID
       AND attributes.Attribute = '1024x768'
     WHERE articles.category_id = 5
    philip, your LEFT OUTER JOIN will behave exactly like an inner join because you have a non-NULL condition in the WHERE clause
    Thank you much! I have tryed this and it works i need now to test more but i think this is what i need. Thank you!!!!


Bookmarks

Posting Permissions

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