MySQL Forums
Forum List  »  Newbie

MySQL Query help
Posted by: Sönke Petersen
Date: June 27, 2012 08:53AM

Hi there, I'm pretty new to mysql. I'm trying to make a query concerning 2 given tables.

Destination:
| Letter-ID | Destination-Country | [..] and

Addresser:
| Letter-ID | Addresser-ID | [..]

Letter-ID and Addresser-ID are unique.

I'm trying to list all addressers (Addresser-ID) who have been writing to addressees in at least 2 different countries. The countries should be in the list, too:
| Addresser-ID | Destination-Country |
| 1 | England |
| 1 | Denmark |
| 1 | Portugal |
| 3 | England |
| 3 | India |
...

Right now, I've no access to the database, but I'm trying to work out a query.

SELECT addresser-id, destination-country
FROM destination a INNER JOIN addresser b ON ( a.letter-id = b.letter-id)
GROUP BY addresser-id, destination-country
HAVING COUNT(addresserid) > 1;

I'm not sure, if the inner join solution (if working) is the best way to do it. Somebody got a better idea?

Thanks in advance.

Options: ReplyQuote


Subject
Written By
Posted
MySQL Query help
June 27, 2012 08:53AM
June 27, 2012 11:09AM
June 27, 2012 12:37PM
June 27, 2012 12:53PM
June 27, 2012 03:37PM
June 27, 2012 05:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.