Selecting Data from two tables
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 posted this at 17:54 — 14th March 2003.
He has: 4,048 posts
Joined: Aug 2000
Are there any keys that you can join on?
mairving posted this at 21:58 — 14th March 2003.
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
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.