我有2个表名为orders
,第2名为rewinding
。
第一orders
有一条记录
id=1, job_code=597, job_name=xyz
第二个rewinding
有一个或多个记录
id=5, job_code=597, weight=254,remarks=foo
id=6, job_code=600, weight=765,remarks=foo
id=7, job_code=597, weight=594,remarks=foo
id=8, job_code=597, weight=54,remarks=foo
现在,我想选择rows and columns
所有code=597
并且只记录orders where job_code=597
答案 0 :(得分:0)
如果orders
中有多个行job_code
并且您只想要一行,则在子查询中使用limit
:
SELECT *
FROM (SELECT o.* FROM orders o WHERE o.job_code = 597 LIMIT 1
) as o597 JOIN
rewinding r
ON o597.job_code = r.job_code;
答案 1 :(得分:-1)
这个怎么样?
SELECT *, orders.id orders_id, rewinding.id rewinding_id
FROM orders
JOIN rewinding ON orders.job_code = rewinding.job_code
WHERE orders.job_code = 597