[英]Select Multiple Rows from Joined Table
I have a table A with a field X that contains a value list like 1,2,3 Then there is a second Table B with a field uid. 我有一个表A,它的字段X包含一个像1,2,3这样的值列表。然后有第二个表B,带有字段uid。 If AX contains 1,2,3 i want to get the rows from table B where uid is 1 or 2 or 3.
如果AX包含1,2,3,我想从表B获得uid为1或2或3的行。
I tried a Join like: 我尝试了像这样的Join:
SELECT b.value FROM A a JOIN B b ON b.uid IN ( a.X )
This kinda works but i only get 1 Result in b.value of course. 这种方法有效,但是我在b.value中只能得到1个结果。 How can I get all the Results?
如何获得所有结果? I know i could just use a second Query, but it is possible to get this in one?
我知道我可以只使用第二个查询,但是有可能将其合并为一个吗?
(I know it is not nice to use such a structure and one should use nn tables, but this is given by the used System) (我知道使用这种结构不好,应该使用nn表,但这是由使用的System给出的)
As you state in your question this is not a good design. 正如您在问题中指出的那样,这不是一个好的设计。 I think the following should work (albeit not with good performance)
我认为以下方法应该有效(尽管性能不佳)
SELECT b.value
FROM A a
JOIN B b ON CONCAT(',',a.X,',') LIKE CONCAT('%,',b.uid,',%')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.