Solved

# How do I joint 2 simple SQL statements?

Posted on 2008-06-11
211 Views
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
Question by:deakie
• 2

LVL 6

Expert Comment

ID: 21759964
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

LVL 6

Accepted Solution

dragos_craciun earned 500 total points
ID: 21759969
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 Closing Comment

ID: 31466146
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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…