Hi There,

I do have 2 tables;
Contacts table, Communications table

Contacts table rows are; contact_number, forename, surname

Communications table rows are; contact_number, number (number is used for emails)

What I have is a little form to check/find out the contact number by filling;
surname forename and email.

Once they filled in I need to run sql query

SELECT contact_number FROM these two tables WHERE forename='$forname' surname='$surname' number='$email'

as well as checking if surname and forename's contact_number matches with given email's contact_number. If exists echo the contact_number to the user.

Thank you!

Re: Sql select from multiple tables 80 80


You could use joins in mysql to perform this.

SELECT cont.contact_number FROM contacts as cont JOIN communications  as comm ON contact.contact_number = comm.contact_number WHERE cont.forename='$forname' AND cont.surname='$surname' AND comm.number='$email'
Re: Sql select from multiple tables 80 80

Thanks Paulrajj,

However I receive this error message;

"SQL Server Database Error: The multi-part identifier "contacts.contact_number" could not be bound. 1" 0

Re: Sql select from multiple tables 80 80

Problem solved!

I did use this query

contacts.forenames, contacts.surname, communications.number, contacts.contact_number
LEFT JOIN communications
ON contacts.contact_number=communications.contact_number
contacts.surname='$surname' AND contacts.forenames='$forenames' AND communications.number='$email'


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.