Amit Sharma Amit Sharma - 1 year ago 83
PHP Question

like clause in sub query not working

I have 2 tables designs and stores, I need to get designs where store id is 'something' and particular on that store id that design should allow.

Example - store id is '401274' then I want designs that should belong to store id= '401274' and on that store id(401274) that design id should be available in design_id_allowed column of store, I have written a subquery but it not working here is syntax error

My query is,

SELECT `designs`.`id`, (SELECT `stores`.`id` as 'store_id' FROM `stores` WHERE `stores`.`id`='401274' And `stores`.`design_id_allowed` like '%#'.`designs`.`id`.'#%') FROM `designs` WHERE `designs`.`store_id` = '401274'

Error is,

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

near 'SELECT
as 'store_id' FROM
='401274'' at line 1

In store table, designs are id's entry like this,
enter image description here

Answer Source

Try this buddy -

  (SELECT  `stores`.`id` as 'store_id'  FROM `stores` WHERE  `stores`.`id`='401274' And `stores`.`design_id_allowed` like '%2629%')
FROM `designs`
WHERE `designs`.`store_id` = '401274'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download