我有两张桌子
在事务表中,与id,date_of_txn,amount等事务相关的所有信息都是字段,在member表中,所有与成员相关的信息,如成员ID,成员名,密码等,两个表都与mid
连接。当我想要通过以下查询运行的成员获取所有事务问题时,问题就在这里:
SELECT * FROM transaction
WHERE amount >=525
and amount <=2500
and txn_issued_by =(select mid from members)
它告诉我:
Error Error : #1242 - Subquery returns more than 1 row
答案 0 :(得分:1)
SELECT * FROM transaction WHERE amount >=525 and amount <=2500
and txn_issued_by IN (select mid from members)
使用IN而不是=
答案 1 :(得分:1)
使用JOIN:
SELECT t.*
FROM transaction t
JOIN members m
ON t.txn_issued_by = m.mid
WHERE t.amount BETWEEN 525 AND 2500