Author |
Topic |
|
Da_Stimulator
DEV Team Forum Moderator
USA
3373 Posts |
Posted - 10 January 2005 : 16:18:11
|
I dont really understand this join stuff yet...
What I'm trying to do is grab information from two seperate tables, that hold basically the same type of information, and display them...
Here's what the database looks like to an extent... (Access)
Table: E_DOWNLOADS d_id d_name (100) d_description (memo) d_cat (numeric, cat id)
Table: E_IMAGES i_id i_name (100) i_description (memo) i_cat i_link (folder & file name for the image)
I want to grab the information from both of these tables for display in a single table, record by record, in chronological order by the id field. d_cat and i_cat are irrelavent. |
-Stim |
|
D3mon
Senior Member
United Kingdom
1685 Posts |
Posted - 10 January 2005 : 17:18:09
|
you make a join on information that is the same in both tables (in most cases the ID), so I'm guessing you'll want something like this:
SELECT d_name, d_description, d_cat, i_name, i_description, i_cat, i_link [get all the fields from both tables] FROM e_downloads [from this table...] INNER JOIN e_images [joining to this table] ON e_downloads.d_id = e_images.i_id [where the id from the first table is the same as the id from the second table]
...by default the order will be by the ID (ascending), even if the ID is not returned in the results. |
Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod "In war, the victorious strategist only seeks battle after the victory has been won" |
Edited by - D3mon on 10 January 2005 17:21:17 |
|
|
sr_erick
Senior Member
USA
1318 Posts |
Posted - 10 January 2005 : 19:17:37
|
You can also do the entire join in the where clause, for this type of join. It's easier that way for beginners, at least I know it was for me when I was first learning. All the tables are seperated by a comma and you don't need to worry about which table goes on which side of the join statement. This won't work for right of left joins though and more of the advanced queries.
SELECT d_name, d_description, d_cat, i_name, i_description, i_cat, i_link [get all the fields from both tables] FROM e_downloads [from this table...], e_images [joining to this table] WHERE e_downloads.d_id = e_images.i_id [where the id from the first table is the same as the id from the second table]
After the WHERE clause you can also use AND, OR and such for additional clumn joins or limiting of the data you want back. |
Erick Snowmobile Fanatics
|
Edited by - sr_erick on 10 January 2005 19:18:58 |
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 11 January 2005 : 21:49:10
|
If you're not comfortable with joins, use the query builder in Access and then copy the SQL statement it generates and tweak as needed. |
|
|
|
Astralis
Senior Member
USA
1218 Posts |
Posted - 12 January 2005 : 00:35:12
|
With joins, there are multiple ways of making a join to get the same effect. |
|
|
|
Topic |
|
|
|