SunQuest
           Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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:
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  
Old August 20th, 2003, 02:53 AM
coume coume is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: France / Finland
Posts: 13 coume User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
[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
and
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

Reply With Quote
  #2  
Old August 20th, 2003, 06:50 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,339 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 7 h 47 m 13 sec
Reputation Power: 891
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

Reply With Quote
  #3  
Old August 20th, 2003, 07:00 AM
coume coume is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: France / Finland
Posts: 13 coume User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old August 20th, 2003, 07:09 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,339 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 7 h 47 m 13 sec
Reputation Power: 891
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

Reply With Quote
  #5  
Old August 20th, 2003, 07:12 AM
coume coume is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: France / Finland
Posts: 13 coume User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hmm how to run the script outside asp? I don't know

but the script is working if I display all the users.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > [MS-SQL] Problem with left join... Any Guru??


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