Select data from three different tables with null data

Posted by user3678972 on Stack Overflow See other posts from Stack Overflow or by user3678972
Published on 2014-05-27T09:15:07Z Indexed on 2014/05/27 9:25 UTC
Read the original article Hit count: 231

Filed under:

I am new in Sql. My question is how to get data from three different tables with null values.

I have tried a query as below:

SELECT *
FROM [USER]
JOIN [Location] ON ([Location].UserId = [USER].Id)
JOIN [ParentChild] ON ([ParentChild].UserId = [USER].Id) WHERE ParentId=7

which I find from this link.

Its working fine but, it not fetches all and each data associated with the ParentId

Something like it only fetches data which are available in all tables, but also omits some data which not available in Location tables but it comes under the given ParentId.

For example: UserId ParentId

          1         7

          8         7

For userId 8, there is data available in Location table,so it fetches all data. But there is no data for userId 1 available in Location table, so the query didn't work for this.

But I want all and every data. If there is no data for userId then it can return only null columns. Is it possible ??

hope everyone can understand my problem.

© Stack Overflow or respective owner

Related posts about sql