When i am add new post that time select multiple category and store in database like 48,52 into single field sub_cat_id
I am try to get value using IN but not get properly
SELECT *
FROM tbl_listing
WHERE status='1' and sub_cat_id IN (52)
ORDER BY tbl_listing.company_name DESC LIMIT 0, 15
I am store value into db like below screenshot
Please help me
If you are passing 48,52
as comma separated numbers as a string to IN
then search is not performed correctly. You have to use FIND_IN_SET
with column and the CSV value.
SELECT * FROM tbl_listing
WHERE status='1'
and ( FIND_INSET( 48, sub_cat_id ) > 0
OR FIND_INSET( 52, sub_cat_id ) > 0 )
ORDER BY
tbl_listing.company_name DESC
LIMIT 0, 15
Refer to:
you can try this...
SELECT * FROM tbl_listing WHERE status=='1' and sub_cat_id IN (48,52) ORDER BY
tbl_listing.company_name DESC LIMIT 0, 15;
try:
SELECT *
FROM tbl_listing
WHERE status='1' and (sub_cat_id like ('%48,') or sub_cat_id like ('%52,'))
ORDER BY tbl_listing.company_name DESC LIMIT 0, 15