Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 How to join tables and columns in sql query
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 10 January 2005 :  16:18:11  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
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  Show Profile  Visit D3mon's Homepage
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
Go to Top of Page

sr_erick
Senior Member

USA
1318 Posts

Posted - 10 January 2005 :  19:17:37  Show Profile  Visit sr_erick's Homepage  Send sr_erick a Yahoo! Message
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
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 11 January 2005 :  21:49:10  Show Profile  Visit dayve's Homepage
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.

Go to Top of Page

Astralis
Senior Member

USA
1218 Posts

Posted - 12 January 2005 :  00:35:12  Show Profile  Send Astralis a Yahoo! Message
With joins, there are multiple ways of making a join to get the same effect.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.29 seconds. Powered By: Snitz Forums 2000 Version 3.4.07