Kuan Kuan - 1 month ago 6x
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?


Use the below query..

   Select username,email ,domain,company
   From users
      join company 
        On email like '%@' || domain