Wordica
Wordica

Reputation: 2597

Get emails based on second table

I'm not too good in mysql and for advanced users it's just one minute. I need only emails from table "users" . Every user has table "profiles" or in other way, every "profiles" entry has user_id. Profiles has also "age" entry. I need emails from users which "age" is >= 40.

SELECT email FROM users WHERE ... ( age from "profiles" table for that user_id >= 40 ) 

Upvotes: 0

Views: 28

Answers (1)

tomtau
tomtau

Reputation: 136

Assuming user_id of "profiles" table is a foreign key referencing a primary key id in "users" table, you can do:

SELECT U.email FROM users U, profiles P WHERE P.user_id = U.id AND P.age >= 40

Upvotes: 2

Related Questions