Trying to write a query for a database that models people. These people hold positions in the organization, and as such they have multiple entries in the positions table. I've also joined from tables that hold email, address, and phone information.
I have the original query similar to this one.
SELECT
P.ID
, N.FIRST
, N.MIDDLE
, N.LAST
, A.AD1
, A.AD2
, A.AD3
, A.CITY
, A.STATE
, A.ZIP
, A.COUNTRY
, PH.NUMBER
, PH.TYPE
, E.TYPE
, E.ADDRESS
FROM
PERSON AS P
JOIN NAME AS N ON P.ID=N.ID,
JOIN ADDRESS AS A ON P.ID=A.ID,
JOIN PHONE AS PH ON P.ID=PH.ID,
JOIN EMAIL AS E ON P.ID=E.ID
I want to join the POSITION
table onto this query, but instead of the join causing the original query to come out with a separate row for each row in the POSITION
table, I would like each row from POSITION
to be appended to the row from the query.
Query for the position table is simply for each of the rows returned from the first query, select * from Position as Pos where Pos.ID={P.id}
where P.ID is from the first query.
A normal result should be like this:
kind of how you would think of joining an order record with the items on the order. I'm thinking this should be a union.
but what I get when I just join the position table is like this:
Is this possible? been looking for days.