Ezilon.com - Target Your Audience, be Seen in Your Region

Selecting Data from two tables

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 82 posts

Joined: Oct 2001

This is so simple. I am frustrated that I cannot do this.

I need to select 2 columns from two different tables:

Select T1.col1, T1.col2, T2.Col1, T2.Col2 from
Table1 T1, Table2 T2

Here is the problem Table 1 has three rows of data
Table 2 has 15 so when I write out the values of the recordset
The values repeat.

Thanks,

Mike

Blessed is the man who fears the LORD, who delights greatly in his commandments. Psalms 112:1

Mark Hensler's picture

He has: 4,044 posts

Joined: Aug 2000

Are there any keys that you can join on?

mairving's picture
Moderator

They have: 2,256 posts

Joined: Feb 2001

What Mark means is are there any fields linking the tables. If so, you need to narrow down the SQL. Here is an example.

Small table - primary key is table_id,
Big table - foreign key is table_id, which links the tables. A query for all of the records would look like so:

<?php
SELECT
* from table1, table2
WHERE table1
.table_id=table2.table_id;
?>

If you only wanted one field, just add an additional statement like:

<?php
SELECT
* from table1, table2
WHERE table1
.table_id=table2.table_id
AND table.table_id='1';
?>

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states