简体   繁体   中英

MySQL: Subqueries with multiple results

I can't find the error in my (my)sql query:

SELECT * 
FROM   KUNDEN 
WHERE  KUNR IN (SELECT DISTINCT KUNR 
                FROM   AUSLEIHE) 

kunr: integer

Everytime it says, that there are multiple results in the subquery . But my target is to check, if the subquery contains the value of kunr. It would be very nice, if you could help me.

What about JOIN

SELECT * FROM   KUNDEN  k 
JOIN AUSLEIHE a ON (k.KUNR  = a.KUNR ) 
(SELECT KUNR 
FROM   AUSLEIHE GROUP BY KUNR)

Try this subquery.

just for laughs

SELECT * FROM   KUNDEN  k 
LEFT JOIN AUSLEIHE a ON (k.KUNR  = a.KUNR )
where   a.KUNR is not null 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM