#1
  1. No Profile Picture
    mrtesting
    Guest
    Devshed Newbie (0 - 499 posts)
    This is one of the value in tab1.
    author : 'new author here'
    quotation : 'test old quote here'
    category : '1' or '2'
    display :'Y'

    when i do this :-
    select * from qquote where category='10' and display='Y' and quotation like '%he%' or author like '%he%'

    MySQL returned this record when it shoud not (or so I thought).

    So, I tried this :-
    select * from qquote where category = '1' and quotation like '%new%' or category = '1' and author like '%new%'

    This should return this record but it did not return anything.

    How do i do the query ?????

    Thanks. Please reply soon.
  2. #2
  3. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    I'd suggest you place some () around your logic. OR takes precedence over AND. So in the first query "author like '%he%' is true, nothing before the OR matters.

    In the second the you are evaluating like this (category='1' and (quotation like '%new' or category='1') and author like '%new')

    All three sections need to be true. The first and third aren't but the second isn't.

    I *believe* this is what you are trying to do:

    select * from qquote where category='10' and display='y' and (quotation like '%he%' or author like '%he%');

    select * from qquote where category='1' and (quotation like '%new%' or author like '%new%');

Similar Threads

  1. SQL Queries Query!!!!!!
    By Paul_Statham in forum MySQL Help
    Replies: 8
    Last Post: April 9th, 2002, 10:14 PM
  2. Dynamic value of select box based on other select box
    By etherwolf in forum HTML Programming
    Replies: 6
    Last Post: October 16th, 2001, 11:11 AM
  3. select box changes other select box...
    By etherwolf in forum PHP Development
    Replies: 6
    Last Post: October 11th, 2001, 12:29 PM
  4. SELECT...WHERE errors using MySQL and PHP3
    By SepodatiCreations in forum MySQL Help
    Replies: 1
    Last Post: December 21st, 1999, 07:25 AM
  5. SELECT...WHERE errors using MySQL and PHP3
    By SepodatiCreations in forum PHP Development
    Replies: 2
    Last Post: December 5th, 1999, 09:21 AM

IMN logo majestic logo threadwatch logo seochat tools logo