Solved

How do I joint 2 simple SQL statements?

Posted on 2008-06-11
3
209 Views
Last Modified: 2010-04-21
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
Comment
Question by:deakie
  • 2
3 Comments
 
LVL 6

Expert Comment

by:dragos_craciun
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

by:
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

by:deakie
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question