Gossamer Forum
Home : General : Databases and SQL :

query help

Quote Reply
query help
I hope this is the right place to ask this. I'm using perl and mysql and I'm having trouble figuring out a query. I have three tables - Activities, Sponsors and Links. In the activities table I want to select all the rows for a given date range. That part is simple and done. But, in this table are three fields in particular for each record where I need to get info from other tables, sponsor1id, sponsor2id and linkid. The first two of these are id's that relate to separate records in the Sponsors table and as part of the query I want to get the SponsorName from the Sponsor table for those two columns. For the linkid field, I need to pull the url from the Links table based upon that records linkid. I'm totally baffled. Can this be done in a single query.

I know normally if I wanted to pull data from two tables, I would do something like

SELECT fields from Activities,Links where Activities.linkid = Links.linkid AND Activities.date = range

But what has me baffled is that I want to pull two records from the Sponsors and one from the Links table for each result returned.

Also, will doing it this way bog down the server / slow down the query dramatically... I figured because there are a lot of records, probably half a million when I finish the first cut, I didn't want to repeat so much data over and over and over again so I created "lookup tables".

If anyone can help I'd be most appreciative.
Subject Author Views Date
Thread query help JerryP 9429 Aug 29, 2002, 11:56 AM
Thread Re: [JerryP] query help
Stealth 9300 Aug 29, 2002, 2:03 PM
Thread Re: [Stealth] query help
JerryP 9245 Aug 29, 2002, 2:57 PM
Thread Re: [JerryP] query help
Stealth 9266 Aug 29, 2002, 5:08 PM
Thread Re: [Stealth] query help
JerryP 9287 Aug 29, 2002, 5:56 PM
Thread Re: [JerryP] query help
videssos 9062 Sep 15, 2002, 8:04 AM
Post Re: [videssos] query help
JerryP 8960 Sep 16, 2002, 10:39 AM