SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What's wrong with my SELECT statement?

    I have a select statement which was working perfect until I had to change it so it would only select entries that were under a certain category "6". For some reason it's selecting all of the entries in the database and not just the ones that are assigned to category 6. Can somebody please tell me what I'm doing wrong?

    Code:
    	   SELECT customer.id
    		, customer.category_id
    		, customer.usrname
    		, menu.company
    		, menu.smlogo
    		, category.name		as c_name
    	     FROM customer
           LEFT OUTER
    	     JOIN menu
    	       ON menu.customer_id = customer.id
           LEFT OUTER
    	     JOIN category
    	       ON category.id = customer.category_id
    	    WHERE menu.status = '1'
    	      AND category.id = '6'
    	 ORDER BY c_name
    John Saunders

  2. #2
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anybody?
    John Saunders

  3. #3
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    696
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Move the criteria in the where clause to the on clauses.

  4. #4
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    swampBoogie,

    Thanks for your response. Can you please give me an example of what you mean? I'm not quite following you.
    John Saunders

  5. #5
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    696
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    SELECT customer.id
    		, customer.category_id
    		, customer.usrname
    		, menu.company
    		, menu.smlogo
    		, category.name		as c_name
    	     FROM customer
           LEFT OUTER
    	     JOIN menu
    	       ON menu.customer_id = customer.id
                  AND menu.status = 1
           LEFT OUTER
    	     JOIN category
    	       ON category.id = customer.category_id
                 AND category.id = 6
    	  ORDER BY c_name

  6. #6
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!
    John Saunders


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
  •