简体   繁体   中英

MySQL INNER JOIN syntax

Can someone "break down" the syntax here. Please. I need to learn this ASAP.

From my limited experience -

firstname and lastname are columns and list is a table.

count(id)>1 is used to check if there is more than one row with the same...

That's it. I don't know what this does but I need to understand it.

SELECT firstname, lastname, list.address FROM list 
INNER JOIN (SELECT address FROM list 
            GROUP BY address 
            HAVING count(id) > 1) dup 
   ON list.address = dup.address

This query will return a list of all names (first and last name), which contain a duplicate address. This part

SELECT address FROM list 
GROUP BY address HAVING count(id) > 1

Gets a list of all the addresses that occur more than once in the table, This is then joined back to the table itself, to return all names which have the same address. This should return a list of all the unique address which have more than 1 name associated with them, along with the names that go along with the addresses.

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