I am wanting to write this query:
SELECT u.userId, uil.interestId, url.regionId FROM users u
JOIN userInterestLink uil USING (userId)
JOIN userRegionLink url USING (userId)
JOIN dealInterestLink dil USING (interestId)
JOIN dealRegionLink drl USING (regionId, dealId)
WHERE dealId = 1
using the code igniter active records class, however I have no ideda how to do the JOIN ... USING
There is no built-in support for
JOIN ... USINGin the active record class. Your best bet would probably change thejoin()function to be like this (the file issystem/database/DB_active_rec.phpin case you don’t know)So then, you can simply use this in your code
join('table', 'USING ("something")')Although, you might want to extend the class instead of modifying it so that you won’t need to do same thing over and over again when you upgrade your CI.
Have a look at this article or this one (or search google) if you want to do so instead.
Or if you don’t want to go all those troubles, you can write a simple helper function that can do the same thing.
Later on, just load the helper and call the function like this
join_using('table', 'key'). It will then produce the same result as you would with the originaljoin()except this one will give youUSINGinstead ofONcondition.For example: