|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
[MS-SQL] Problem with left join... Any Guru??
Hello,
I am using this code: Code:
conn2Query="select * from PDM_USER_2 left outer join PDM_USER_DOSE_2 on PDM_USER_2.mainkey = PDM_USER_DOSE_2.userid and periodid ="&RequestedPeriodID&" where PDM_USER_DOSE_2.userid is null ORDER BY "&Column&" "&Order&"" It is working fine WITH one MAJOR exception ![]() I can retrieve all the fields from the PDM_USER_2 except the MAINKEY.... And that's very annoying, I'm stuck! the problem must come from the part: Code:
PDM_USER_2.mainkey = PDM_USER_DOSE_2.userid Code:
PDM_USER_DOSE_2.userid is null But I cannot change them, as I need to retrieve all the users from PDM_USER_2 that have no record for a specific period in PDM_USER_DOSE_2 Any idea how to get my fields MAINKEY from PDM_USER_2 ??? Thanks in advance , cos I'm really really stuck! Ludo |
|
#2
|
||||
|
||||
|
your question is very nicely written and it's quite clear what you want
however, you should already be getting MAINKEY if this is indeed a column in the PDM_USER_2 table do yourself a favour, don't use "select star" instead, list all the columns you want in this particular case, where you are actually looking for rows in the left table that don't have a match in the right table, "select star" will always include all columns from both tables, but the columns from the right table will all contain nulls, which, when you think about it, is exactly what you asked for, so why ask for columns from the right table? rudy |
|
#3
|
|||
|
|||
|
Hello
![]() Ok, I will try to explain a bit more ![]() With the result of this query I display a table: Code:
Name | col1 | dose | .... -------------------------------- Ludo | 3 | | Fredo | 5 | | Jack | 5 | | ...... It is normal to have the dose column empty as they have no result for this period.. However, I need that their name link them to their profile ex: Code:
<a href="goto.asp?id=3">Ludo</a> In this code the "3", is the MAINKEY from the PDM_USER_2. But with the query, mentionned in my first post, the MAINKEY from PDM_USER_2 allways return "" ... then all the links are like Code:
<a href="goto.asp?id=">Ludo</a> <a href="goto.asp?id=">Fredo</a> <a href="goto.asp?id=">Jack</a> and that's why I have to find how to get this MAINKEY, which is not taken actually! Any idea? thxs Ludo |
|
#4
|
||||
|
||||
|
run your query outside of your asp script and see what it returns
if MAINKEY is actually a column in the left table of a left outer join, you will see it i'm thinking it's your script that's the problem |
|
#5
|
|||
|
|||
|
hmm how to run the script outside asp? I don't know
![]() but the script is working if I display all the users. |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > [MS-SQL] Problem with left join... Any Guru?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|