R
R
Roman Koff2017-03-03 14:26:18
SQL
Roman Koff, 2017-03-03 14:26:18

How to formulate a cross-select query from a SQL table?

There is a table with related tables defined as follows:
Pubs
.PubId
.PubName
PubNodes
.PubNodeId
.PubPtr (--> Pubs.PubId)
.NodePtr
PubTargets
.PubTargetId
.PubPtr (--> Pubs.PubId)
.TargetPtr
PubSections
.PubSectionId
.PubPtr (--> Pubs.PubId)
.SectionPtr
What would an SQL query look like to get a list of Pubs for (NodePtr = A) AND (TargetPtr = B) AND (SectionPtr = C)?
I understand that, it seems, you need to join, but I don’t understand how.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Draconian, 2017-03-03
@Zarinov

select *
from pubs p
    join pubnodes pn on p.pubId = pn.pubptr
    join pubtargets pt on p.pubId = pt.pubptr
    join pubsections ps on p.pubId = ps.pubptr
where (pn.NodePtr = A) AND (pt.TargetPtr = B) AND (ps.SectionPtr = C)
;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question