Skip to content
Advertisement

SQL Join 3 tables with null values

I have a query that returns members, their last visit and their last payment. My problem is that it doesn’t return members without a visit and/or a payment.

I previously didnt include the last visits and I then had a query with LEFT and RIGHT JOINs instead of INNER but when I added the visit table I received som help to include it but we didn’t notice that we were missing the members with null values in visit or payment.

I’ve tried applying LEFT and RIGHT JOINs without any luck. I’ve also tried adding eg. “OR (pt.member_id IS NULL)” also without success.

I want to get a result where visit and/or payment can be null.

I hope I make sense and that someone can help me 🙂

MySQL 5.6

Advertisement

Answer

A little tweak on Thorsten Kettner’s answer made it work:

Thanks everyone 🙂

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