Click to See Complete Forum and Search --> : Joining Two Tables


Rik Comery
09-10-2003, 03:05 AM
Hi. I am very new to this so please forgive my ignorance.

I have two tables in a database. One called "Clients" and the other called "Clients_Docs". The tables contain the following fields. (i have excluded many as they are irrelivant for this question).

Clients
ID (primary)
First_Name
Surname
etc

Clients_Docs
DocID (primary)
ID
Document_Type
etc

To accompany this, i have a PHP form which populates the Clients table, and gives the entry a unique id in the ID field. Once a client has been added, i have a type of update form where you can add different document types for that client. This information is written to the Clients_Docs table and inserts the unique ID value from the first table into the ID field.

This all works fine. My problem is when i try to create a query. If i search for any field in the Clients table, the results are fine, but how do i select from both tables.

for example, i may want to find all clients whose first name is Rik, and have been sent a prospectus document. (first name is in Clients table and prospectus document is in Clients_Docs)

I have tried to use a join in my select query, but to be honest, i have not found information on this that is easy to understand. As i said, i am new to this.

Can anyone help please.

eomer
09-11-2003, 06:01 PM
What database software are you using? If you are using MySQL then the answer would be something like
select * from Clients, Clients_Docs where Clients.ID = Clients_Docs.ID... Most database software will be the same, but with just a little bit different sytax. This I know will work under MySQL.
Hope that helps.

Rik Comery
09-12-2003, 03:39 AM
That worked fine. Thanks eomer

eomer
09-12-2003, 10:37 AM
Good. Glad to hear that.