I have:
- a
couponstable with a column calledowner_idandid - and an
ownerstable with a column calledidandwebsite_url.
I’d like to get owners.website_url using only coupons.id (which is provided in a php variable $coupon_id.
Here’s my best shot:
SELECT owners.website_url
FROM owners o
LEFT JOIN coupons c
ON o.id = c.owner_id
WHERE c.id='$coupon_id'
LIMIT 1
Is this correct? I put LIMIT 1 beacause there are many coupons per owner.
It looks correct, but it’s pointless to use a
LEFT JOINthere since you are filtering away the failed joins in yourWHEREclause. Just useJOIN.You also shouldn’t need the
LIMITclause since all coupons should have unique ids (assuming thatidis a primary key) and each coupon has only one owner.