Kuan Kuan - 1 year ago 73
SQL Question

How to group users by email in SQL

I wonder how can I query username base on its email address:

I have one table called users:

username email
AAAA A@A1.com
BBBB B@B1.com
CCCC C@C1.com
DDDD D@A1.com

And one table called company:

company domain
ComA A1.com
ComB B1.com
ComC C1.com

Any simple query can get all usernames which has email domain listed in company table?

Answer Source

Use the below query..

   Select username,email ,domain,company
   From users
      join company 
        On email like '%@' || domain 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download