since "and" has higher precedence than "or", you should be careful, try the following:select book_id,book_title from allbooks,author,series,publish 
where 1=1 
and (author_name like 'owen%' or author_name like '%owen' or author_name like '%owen%') 
and (series_name Like 'life%' or series_name Like '%life' or series_name Like '%life%') 
and (publish_name like 'dut%' or publish_name like '%dut' or publish_name like '%dut%')
and allbooks.author_id=author.author_id 
and allbooks.series_id=series.series_id 
and allbooks.publish_id=publish.publish_id 
order by book_id 
or just doselect book_id,book_title from allbooks,author,series,publish 
where 1=1 
and author_name like '%owen%'
and series_name Like '%life%'
and publish_name like '%dut%'
and allbooks.author_id=author.author_id 
and allbooks.series_id=series.series_id 
and allbooks.publish_id=publish.publish_id 
order by book_id

解决方案 »

  1.   

    '%dfg%' 对于: zzzzzdfg 和dfgzzzz都可以查出:select book_id,book_title from allbooks,author,series,publish where 1=1 and( author_name like '%owen%' and series_name Like '%life%' and publish_name like '%dut%' and allbooks.author_id=author.author_id and allbooks.series_id=series.series_id and allbooks.publish_id=publish.publish_id order by book_id 
      

  2.   

    即使你要用or 也要把or扩起来:select book_id,book_title from allbooks,author,series,publish 
    where 1=1 and (author_name like 'owen%' or author_name like '%owen' or author_name like '%owen%') and (series_name Like 'life%' or series_name Like '%life' or series_name Like '%life%') and (publish_name like 'dut%' or publish_name like '%dut' or publish_name like '%dut%') and allbooks.author_id=author.author_id 
    and allbooks.series_id=series.series_id 
    and allbooks.publish_id=publish.publish_id 
    order by book_id
      

  3.   

    --and和or组合时,应该加上必要和括号,试试下面是否是你想要的.select book_id,book_title 
    from allbooks a
    join author b on a.author_id=b.author_id
    join series c on a.series_id=c.series_id
    publish d on a.publish_id=d.publish_id
    where (author_name like 'owen%'
    or author_name like '%owen'
    or author_name like '%owen%')
    and (series_name Like 'life%'
    or series_name Like '%life'
    or series_name Like '%life%')
    and (publish_name like 'dut%'
    or publish_name like '%dut'
    or publish_name like '%dut%')