Skip to content
Advertisement

Full Outer Join failing to return all records from both tables

I have a pair of tables I need to join, I want to return any record that’s in tableA, tableB or both. I think I need a FULL OUTER JOIN

This query return 1164 records

And this one return 3339 records

And this one returns 3369 records (so there must be 30 records in tableA that aren’t in tableB)

I want to obtain a list of all matching records in either table. The query above returns 3369 records, so a FULL OUTER JOIN should also return 3369 rows (I think). My best effort so far is shown below. It returns 1164 rows and returns what looks to me to be a left join between tableA and tableB.

Help appreciated. (if this looks question looks familiar, it’s a follow-on question to this one )

UPDATE – Sorry (@forpas) to keep moving the goalposts – I’m trying to match test data to real-data scenario’s.

For this data, I’d hope to see 4 rows of data ‘A’ from tableA only, ‘B’ and ‘C’ from both tables, and ‘D’ from table B only. I’m after the 5th April records only! The query (shown above) suggested by @forpas works except that the ‘A’ record in tableA doesn’t get returned.

UPDATE – FINAL EDIT AND ANSWER!

Ok, the solution seem to be to concetenate the two fields together before joining….

Advertisement

Answer

The condition for the date should be placed in a WHERE clause:

or:

See the demo.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement