-1

I am trying to figure what is wrong i am doing

Here is the JOIN i have

select * from table1 left outer join table2 on 
            table1.fkID = table2.fkID
            where table2.fkID= 500 order by 1 desc 

i should multiple records but i am only getting 1, am i doing something wrong here

Jan
  • 85
  • 7
  • please provide sample data. It makes the ask more clearer – Venkataraman R Dec 01 '20 at 16:35
  • Side Note: [Bad Habits to Kick : ORDER BY ordinal](https://sqlblog.org/2009/10/06/bad-habits-to-kick-order-by-ordinal). This could especially problematic considering you are using `SELECT *`. – Thom A Dec 01 '20 at 16:38

1 Answers1

1

You need to move the condition in the where clause to the on clause:

select *
from table1 left outer join
     table2
     on table1.fkID = table2.fkID and
        table2.fkID= 500
 order by 1 desc;

The where clause filters out NULL values turning the outer join into an inner join.

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786