3

I have two tables in MySQL, customer and contacts

each row in customer can have multiple rows in contacts and contacts.company will equal customer.sequence

how can i run a query to search both tables and return the results from the customer table only?

for example, if i have this data:

customer:

sequence = 123
company = Company A

sequence = 321
company = Company B

contacts:

company = 123
forename = John

company = 123
forename = Steve

company = 321
forename = Joe

company = 321
forename = Andy

company = 321
forename = John

and i search for Andy - it should return Company A

If i search for John, it should return Company A and Company B

charlie
  • 415
  • 4
  • 35
  • 83
  • Your question is not clear enough. What are you searching both tables for if you only want results from the customer table? SELECT * FROM CUSTOMER; will do that without searching both tables. – kojow7 Jun 01 '15 at 22:28
  • By which criterion do you want to filter your results? – TimoStaudinger Jun 01 '15 at 22:28
  • 2
    possible duplicate of [How to join two tables mysql?](http://stackoverflow.com/questions/3536283/how-to-join-two-tables-mysql) – Andy Hoffner Jun 01 '15 at 22:29
  • take a look at my update - hopefully explains a bit better – charlie Jun 01 '15 at 22:35

1 Answers1

0
select
    C.Company
from
    Customer,
    Contacts
where
    Customer.Sequence = Contacts.Company
    and Contacts.Forename = '<your search name goes here>'