Okay i have mysql query, and i’d like to search both parameters in table_1
i’ll try showing the idea with “php”
if(table_2_params.params_id == 124){
//select LIKE "%EXTEC (Sandvik)%" from table_2_params.nosaukums
}
elseif(table_2_params.params_id == 126){
//SELECT FROM table_2_params WHERE nosaukums is BETWEEN "2010" AND "2012"
}
I want to query display first AND second parameter…(both of them to match)
daymn i hope you will understand what i want to say…
Okay here’s the
mysql query:
SELECT table_1 . * , table_2_params . *
FROM table_1, table_2_params
WHERE table_1.pamat_kat_sad = '756'
AND table_1.preces_id = table_2_params.preces_id
AND (
(
table_2_params.params_id =124
AND table_2_params.nosaukums LIKE "%EXTEC (Sandvik)%"
)
AND (
table_2_params.params_id =126
AND table_2_params.nosaukums
BETWEEN "2010"
AND "2012"
)
)
ORDER BY table_1.preces_id DESC
Problem might be that the table_2_params.nosaukums type is longtext …
If i select only with
AND (
table_2_params.params_id =126
AND table_2_params.nosaukums
BETWEEN "2010"
AND "2012"
)
it displays correct year…
AND if i select only with
(
table_2_params.params_id =124
AND table_2_params.nosaukums LIKE "%EXTEC (Sandvik)%"
)
it also displays correct values…
But i cant make them both work together..
Please help me!
Thank you!
If you want two sets of conditions just use
OR. You should also note that joins between tables should be performed using(INNER|LEFT) JOIN:And finally your query may perform poorly, since mysql won’t be able to use any index with
AND table_2_params.nosaukums LIKE '%EXTEC (Sandvik)%'