General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old December 28th, 2002, 09:55 AM
Chrissie Chrissie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 13 Chrissie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Easy Join Troubles ?!

I'm kinda new to SQL...probably someone can give me hand to a Join statement...
PHP Code:
 SELECT topic_idsection_idtitlethe_timethe_text FROM tblNews ORDER BY the_time DESC LIMIT 4

SELECT image FROM tblTopics WHERE topic_id 
= `topic_id


I'd like to join those statements...so I can use the selected topic_id from the first statement for retrieving the value from the image field...

Reply With Quote
  #2  
Old December 28th, 2002, 02:34 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
Do both tables have a topicID? i.e., is topic_id the primary key in tblTopics and the foreign key in tblNews? if so, how about:

select tbltopics.topic_id, section_id, title, the_time, the_text, tbltopics.image FROM tblNews INNER JOIN tbltopics on tblNews.topic_id = tblTopics.topic_id
where tbltopics.topic_id = 'topic_id'

I haven't tried it myself, so let me know if you run into any problems, but it should work.


Last edited by aspnewbie : December 28th, 2002 at 02:37 PM.

Reply With Quote
  #3  
Old December 28th, 2002, 03:11 PM
Chrissie Chrissie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 13 Chrissie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot..have it working now..

SELECT n.topic_id as topic_id, n.title as title, n.the_time as the_time, n.the_text as the_text, t.image as image_topic FROM tblNews n, tblTopics t WHERE n.topic_id = t.topic_id ORDER BY the_time DESC LIMIT 4

it's a little different...but it does the same...don't know which one is better...

Reply With Quote
  #4  
Old December 28th, 2002, 03:17 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
good for you. code is pretty much the same.

I was thinking (and I could have been wrong on this front) that there was only one item per topic and only one record would be returned, so I didn't include the order by clause.

Last edited by aspnewbie : December 28th, 2002 at 03:20 PM.

Reply With Quote
  #5  
Old December 28th, 2002, 04:14 PM
Chrissie Chrissie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 13 Chrissie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks...there can be more items for every topic...
so item - topic : many - one

I wonder..is there some tool which can easily create these kind of statements?? Statements with Inner / Left / Right joins...that would make life a lot easier

Reply With Quote
  #6  
Old December 29th, 2002, 09:16 AM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
MS Access can write SQL statements for you. When you create a Query (by dragging and dropping fields from the table you require), you can click on the SQL view to see the SQL. However, it's usually possible to write more succinct statements yourself.

It would be great if there was another tool! Anybody else out there have any recommendations?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Easy Join Troubles ?!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway