[Webinar] Streamline your web hosting managementRegister Today

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 219

# How do I joint 2 simple SQL statements?

I have two simple sql statements that I need to join...how would I do that?
P.SEQUENCE is the same as D.SEQUENCE
AND P.BILL is the same as M.IDENT

Here are the statements:
SELECT P.BILL, P.SEQUENCE, P.LOCATION, P.TYPE
FROM dbo.POLICY P
WHERE P.BILL = '24680'

SELECT M.IDENT, D.SEQUENCE, I.IDENT, S.IDENT, D.*
FROM BILL M (NOLOCK),
INVOICE I ,
STATUS S ,
STATUSDETAIL D
WHERE M.IDENT = '24680'
AND I.IDENT = '13579'
AND I.BILL = M.IDENT
AND S.INVOICE = I.IDENT
AND D.STATUS = S.IDENT
0
deakie
• 2
1 Solution

Commented:
SELECT M.IDENT, D.SEQUENCE, I.IDENT, S.IDENT, D.*
FROM BILL M (NOLOCK),
INVOICE I ,
STATUS S ,
STATUSDETAIL D,
dbo.POLICY P
WHERE M.IDENT = '24680'
AND I.IDENT = '13579'
AND I.BILL = M.IDENT
AND S.INVOICE = I.IDENT
AND D.STATUS = S.IDENT
AND P.SEQUENCE = D.SEQUENCE AND P.BILL = M.IDENT
0

Commented:
sorry, I forgot the columns:

SELECT M.IDENT, D.SEQUENCE, I.IDENT, S.IDENT, D.*, P.LOCATION, P.TYPE
FROM BILL M (NOLOCK),
INVOICE I ,
STATUS S ,
STATUSDETAIL D,
dbo.POLICY P
WHERE M.IDENT = '24680'
AND I.IDENT = '13579'
AND I.BILL = M.IDENT
AND S.INVOICE = I.IDENT
AND D.STATUS = S.IDENT
AND P.SEQUENCE = D.SEQUENCE AND P.BILL = M.IDENT
0

Author Commented:
Thanks so much for your quick response....of course your solution works exactly as expected and the results are what I needed!!
0

## Featured Post

• 2
Tackle projects and never again get stuck behind a technical roadblock.