result is not what expected...

G

Guest

hello,
I wrote this code

SELECT C_PROTO.ID, [MIA OTHDEMO].X
FROM C_PROTO LEFT JOIN (SELECT "X" AS X, D_OTHDEMO.ID AS ID FROM D_OTHDEMO)
AS [MIA OTHDEMO] ON [MIA OTHDEMO].ID=C_PROTO.ID

table C_PROTO has 114 records while D_OTHDEMO only 15 (and [MIA D_OTHDEMO]
too I suppose!).

What I would like is to have two columns: one listing all the ID from
C_PROTO and one showing "X" ONLY where C_PROTO.ID=D_OTHDEMO.ID (and [MIA
D_OTHDEMO].ID)

But this is nto working: it shows "X" on for any C_PROTO record!!!

Why?
Rocco
 
P

Pat Hartman

SELECT C_PROTO.ID, IIf(IsNull([MIA OTHDEMO].ID),Null, "X") As colX
FROM C_PROTO LEFT JOIN [MIA OTHDEMO] ON [MIA OTHDEMO].ID=C_PROTO.ID
 
G

Guest

Thank you very much!
Do you know what was wrong with my statement?

Pat Hartman said:
SELECT C_PROTO.ID, IIf(IsNull([MIA OTHDEMO].ID),Null, "X") As colX
FROM C_PROTO LEFT JOIN [MIA OTHDEMO] ON [MIA OTHDEMO].ID=C_PROTO.ID
rocco said:
hello,
I wrote this code

SELECT C_PROTO.ID, [MIA OTHDEMO].X
FROM C_PROTO LEFT JOIN (SELECT "X" AS X, D_OTHDEMO.ID AS ID FROM D_OTHDEMO)
AS [MIA OTHDEMO] ON [MIA OTHDEMO].ID=C_PROTO.ID

table C_PROTO has 114 records while D_OTHDEMO only 15 (and [MIA D_OTHDEMO]
too I suppose!).

What I would like is to have two columns: one listing all the ID from
C_PROTO and one showing "X" ONLY where C_PROTO.ID=D_OTHDEMO.ID (and [MIA
D_OTHDEMO].ID)

But this is nto working: it shows "X" on for any C_PROTO record!!!

Why?
Rocco
 
P

Pat Hartman

I don't really know. Probably the problem was that the inner select was
returning more than a single column. In any event a simple left join is
more efficient than a subselect.
rocco said:
Thank you very much!
Do you know what was wrong with my statement?

Pat Hartman said:
SELECT C_PROTO.ID, IIf(IsNull([MIA OTHDEMO].ID),Null, "X") As colX
FROM C_PROTO LEFT JOIN [MIA OTHDEMO] ON [MIA OTHDEMO].ID=C_PROTO.ID
rocco said:
hello,
I wrote this code

SELECT C_PROTO.ID, [MIA OTHDEMO].X
FROM C_PROTO LEFT JOIN (SELECT "X" AS X, D_OTHDEMO.ID AS ID FROM D_OTHDEMO)
AS [MIA OTHDEMO] ON [MIA OTHDEMO].ID=C_PROTO.ID

table C_PROTO has 114 records while D_OTHDEMO only 15 (and [MIA D_OTHDEMO]
too I suppose!).

What I would like is to have two columns: one listing all the ID from
C_PROTO and one showing "X" ONLY where C_PROTO.ID=D_OTHDEMO.ID (and [MIA
D_OTHDEMO].ID)

But this is nto working: it shows "X" on for any C_PROTO record!!!

Why?
Rocco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

why this wont work? 1
alias...don't alias at all 5
Query to find missing data 4
Create a distinct Join 3
not in criteria fails 2
Query loses records? 5
Subqueries 4
Union query and exclusion of data 4

Top