根据另一个表中的一行从表中选择两行

时间:2014-12-28 00:17:38

标签: mysql

这是我的查询:

$query = "SELECT t1.one_field,t2.another_field FROM table_one t1,
table_two t2 WHERE t2.flag = 2 AND (t1.id = t2.id1 OR t1.id = t2.id2)
AND (t2.id1 = '$comparison' OR t2.id2 = '$comparison') LIMIT 1";

我尝试使用GROUP BY,DISTINCT,UNIQUE(...)但却无法提取我想要的内容......我总是提取 another_field 和一个 one_field 而不是两个 one_field ......完成此任务的最佳方式是什么? Tyvm ...

表1

one_field | id
example1 | id_example1
example2 | id_example2

表2

another_field | flag | id1 | id2
need_to_get | 2 | id_example1 | id_example2

我想得到什么

example1, example2, need_to_get (don't care if result is array or associative)

我得到了什么

example2, need_to_get (expected, since one of the results gets overridden since it has the same field_name...)

0 个答案:

没有答案