|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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%'); |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > select * from tab1 where quote like '%new%' or author like '%new%' ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|