Reputation: 3867
Let's presume I have the following two tables:
Contacts
id (INT PRIMARY)
name (VARCHAR)
Emailsemail_Id (INT PRIMARY)
email_address (VARCHAR)
contacts_id (INT > the link to the Contacts table)
These two tables are linked by contacts_id, so basically each contact may have multiple e-mail addresses associated to it. How could I make an SQL query, which finds EVERY contact, whose email address (email_address) field is LIKE query?
Upvotes: 0
Views: 37
Reputation: 941
You can use left joins it will give all results
select contacts.* from contacts left join Emails on(contacts.id=Emails.contacts_id) where Emails.email_address LIKE '%text%'
ignore syntax error if any.
Upvotes: 1
Reputation: 1396
Try this:
SELECT DISTINCT ContactId FROM Contacts AS C
INNER JOIN Email AS E ON E.contactID = C.ContactID
WHERE E.Email LIKE '%Text%'
Upvotes: 1