1

I have 2 table. Objects and properties. Properties table has properties of the object. But it is possible that the object does not have any properties. I would like to make a query so that I get all the objects that have properties(value in property column) and all the objects that dont have properties(in this case the property column will be empty)

EXAMPLE: Simplified query that gives the same result

SELECT 
row_number () OVER() AS id,
seire.id seire_id,
tegevus.arenguvajadus
FROM andmed seire
RIGHT OUTER JOIN tegevused tegevus ON  seire.id = tegevus.seire_id
WHERE tegevus.aktiivne = true

Data example:

andmed:

Id, Data

1 , ...
2, ... 

tegevused

id, aktiivne, arenguvajadus, seire_id

1, true, something something, 1

1, true, something2 , 1

Expected result

  ID, Seire_id, arenguvajadus

    1, 1, something something

    2, 1, something2

    3, 2,    
5
  • 1
    What is the problem? Seems like simple LEFT JOIN to me. Commented May 25, 2017 at 6:38
  • @ŁukaszKamiński Nope, LEFT JOIN does not solve this. I still get the same result where i only get object that have properties. Probabli UNION would be solution. 1 SELECT for object with properties and another for whidout properties Commented May 25, 2017 at 6:57
  • if left join did not help - use right outer join Commented May 25, 2017 at 7:08
  • @VaoTsun Still nope Commented May 25, 2017 at 7:16
  • then I'd like to see the stucture, data sample, query and failing result Commented May 25, 2017 at 7:17

1 Answer 1

1

You need to remove that LEFT JOINed table from your WHERE. I assume tegevused is properties.

SELECT 
row_number () OVER() AS id,
seire.id seire_id,
tegevus.arenguvajadus
FROM andmed seire
LEFT OUTER JOIN tegevused tegevus ON  seire.id = tegevus.seire_id AND tegevus.aktiivne = true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.