query works till I add where clause

Discussion in 'MySQL' started by lektrikpuke, Aug 25, 2009.

  1. #1
    Hi y'all,

    This query seems to work just fine:

    SELECT book_cat_name.cat_code, book_cat.book_id, book.book_id, book.book_link, book.expires, book.book_code, book.promotion, book.ad_name, book_cat_name.ad_img_url FROM (book_cat_name INNER JOIN book_cat ON book_cat_name.cat_code = book_cat.cat_code) INNER JOIN book ON book_cat.book_id = book.book_id

    Until I add this (no results):

    WHERE book_cat.cat_code like 'books-bath-plumbing'

    The ad_img_url was in book, but I want to move it to book_cat_name so I don't have so much repitition/wasted space.

    book_cat_name is related to book_cat via cat_code
    book_cat is related to book via book_id

    I have also tried:

    SELECT book_cat_name.cat_code, book_cat.book_id, book.book_id, book.book_link, book.expires, book.book_code, book.promotion, book.ad_name, book_cat_name.ad_img_url FROM book_cat_name, book_cat, book WHERE book_cat_name.cat_code = book_cat.cat_code AND book_cat.book_id = book.book_id

    Which works fine till I add:

    AND book_cat.cat_code like 'books-bath-plumbing'

    Any help?

    Thanks.

    Rob :D
     
    Last edited: Aug 25, 2009
    lektrikpuke, Aug 25, 2009 IP
  2. UtemptMe - Ed

    UtemptMe - Ed Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try: OR book_cat.cat_code like 'books-bath-plumbing'
     
    UtemptMe - Ed, Aug 28, 2009 IP
  3. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    Thanks for the reply, but I'm pretty sure that's not going to help. If you use or, that will negate the entire query before it (if the part following the or is true - and it will be).

    Thanks again.

    Any other ideas anybody?
     
    lektrikpuke, Aug 28, 2009 IP
  4. Lavee

    Lavee Well-Known Member

    Messages:
    234
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Try book_cat.cat_code like 'books-bath-plumbing%'

    Thanks

    Lavee
     
    Lavee, Sep 9, 2009 IP