0

我有两张表说 Listings 和 Catalog_Options

清单

listing_id
catalog_option_1
catalog_option_2
catalog_option_3

目录_选项

id
value

这里catalog_option_1, catalog_option_2, catalog_option_3包含映射到 Catalog_Options 表的 id 的 id。我想读取所有 3 的值并将其显示在一行中,用于 Listing_id 说 list_1

4

3 回答 3

1

尝试这个

 SELECT * FROM `catalog_options` 
 where id in
 (SELECT catalog_option_1 FROM `listings` 
 union
 SELECT catalog_option_2 FROM `listings`
 union
 SELECT catalog_option_3 FROM `listings`)
于 2013-05-23T07:32:19.197 回答
0

尝试这个:

SELECT l.listing_id,c1.value as ca1,c2.value as ca2,c3.value as ca3 FROM listing l
   JOIN catalog_option c1 on c1.id = l.catalog_option_1
   JOIN catalog_option c2 on c2.id = l.catalog_option_2
   JOIN catalog_option c3 on c3.id = l.catalog_option_3;
于 2013-05-23T07:17:25.763 回答
0

如果我理解正确,你需要试试这个:

SELECT
    GROUP_CONCAT(l.listing_id),
    GROUP_CONCAT(c.value)
FROM
    Listings l
LEFT JOIN Catalog_Options c
    ON c.id = RIGHT(l.listing_id,1)
于 2013-05-23T07:17:52.637 回答