результат 1 из таблицы 1:
select types from table1 where id = 123456;
результат:
934046, 934049
то результат 1 как параметр таблицы 2:
select GROUP_CONCAT(name) from table2 where id in (
select types from table1 where id = 123456
);
но результат 1 является строковым значением, поэтому результат:
NULL
infact Я хочу получить это:
select GROUP_CONCAT(name) from table2 where id in ('934046', '934049');
or
select GROUP_CONCAT(name) from table2 where id in (934046,934049);
но это может все еще так:
select GROUP_CONCAT(name) from table2 where id in ('934046,934049');
1.
select REPLACE(types,',','\',\'') types from table1 where id=123456
1.1
result: 934046',' 934049
1.2
select GROUP_CONCAT(name) from table2 where ids in (
select REPLACE(types,',','\',\'') types from table1 where id=123456
);
2.
select CONCAT('\'',REPLACE(types ,',','\',\''),'\'') from table1 where
id=123456
2.1
reuslt: '934046',' 934049'
2.2
select GROUP_CONCAT(name) from table2 where ids in (
select CONCAT('\'',REPLACE(types ,',','\',\''),'\'') from table1 where
id=123456);
это строковое значение не может быть в качестве параметра. Что делать, чтобы получить идентификаторы правильно?
select GROUP_CONCAT(t.name) from table2 t
where exists(
select 1 from table1
where id = 123456
and LOCATE(concat(', ', t.id, ',') , concat(', ', types, ',') )>0
)
$query = "select types from table1 where id = 123456";
$result = mysql_query($query) or die(mysql_error());
$array = array();
while($row = mysql_fetch_array($result))
{
$array[] = $row['types'];
}
$array = implode(",",$array);
$query2 = "select GROUP_CONCAT(name) from table2 where id in ($array)";
Я создал код с другим запросом.
types
является varchar, тоselect GROUP_CONCAT(name) from table2 where id in ('934046', '934049')
является подходящим для использования