Amit Sharma Amit Sharma - 5 months ago 12
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
stores
.
id
as 'store_id' FROM
stores
WHERE
stores
.
id
='401274'' at line 1


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

Answer

Try this buddy -

SELECT
  `designs`.`id`,
  (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'
Comments