|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
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. ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Joining tables query question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|