MySQL Forums
Forum List  »  Newbie

Re: Compare 2 fields in different tables using IF
Posted by: Purvez Desai
Date: February 19, 2018 05:17AM

I have finally managed to resolve my problem as follows:

-----------------
select 'various' from tour_det
inner join tour_hdr on tour_det.tourhdrid = tour_hdr.id
inner join diet_anal on diettour_id = tour_det.id and diettour_type = 'TourDet' and tour_hdr.paxno != tour_det.paxno
OR
diettour_id = tour_hdr.id and diettour_type = 'TourHdr' and tour_hdr.paxno = tour_det.paxno

-----------------

There were 2 things that I didn't know about joins which I've learnt.

1. You can use an OR clause to define different join conditions. However by itself that is not enough because when the diet_anal table has entries for both the tour_hdr and tour_det then both sets are included.

2. You can use fields that are not in any of the join tables but available in the query to define additional conditions.

I hope this information proves useful to someone else.

Options: ReplyQuote


Subject
Written By
Posted
Re: Compare 2 fields in different tables using IF
February 19, 2018 05:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.