ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 27th, 2003, 03:55 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
Joining tables query question

I have a Products table that is joined to a Subjects table. Two of the fields in my Productstable are joined to the same Subjectstable: Subject & Subject2.
I'm having trouble getting the subject2 to appear as a word rather than a number.

Here's my query so far:

Code:
sql = "SELECT * FROM products, subject WHERE products.pCode = '" & pCode & "' AND subject.subjectID = products.subject"


This gives me the right result for subject1, but if I add

Code:
AND products.subject2


to the end of my query, I get no results returned because it's probably looking for a product where the first & second subject both equal the same thing (which they never do).

So how do you tell subject2 to look for a different number?

Reply With Quote
  #2  
Old October 27th, 2003, 04:02 PM
kkong's Avatar
kkong kkong is offline
Monkey Magic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: UK
Posts: 103 kkong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to kkong
Hi,

looking at your sql and from what you've said above, you just do the same as the first one but add the field name that matchs products.subject2. So something like:


Code:

AND products.subject2 = subject.matchingfieldforsubject2


Kong.

Reply With Quote
  #3  
Old October 27th, 2003, 04:12 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
The thing is products.subject & products.subject2 both link to subject.subjectID, but each one has a different number from that field.

Code:
sql = "SELECT * FROM products, subject WHERE products.pCode = '" & pCode & "' AND products.subject = subject.subjectID AND products.subject2 = subject.subjectID"


This gives me:

Subject 1: Ancient History; Subject 2: 17

Reply With Quote
  #4  
Old October 27th, 2003, 04:21 PM
kkong's Avatar
kkong kkong is offline
Monkey Magic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: UK
Posts: 103 kkong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to kkong
Hi,

what happens if you remove the first join and leave the second join in? Do you get the text instead of the number?

Kong.

Reply With Quote
  #5  
Old October 27th, 2003, 04:41 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
As usual, when I post a thread on here, I find a solution to my problem soon after except that I don't need the above SELECT statement anymore.

Thanks anyway.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Joining tables query question


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT