How to fetch data from 2 different tables in mysql -
i have 2 tables:
subscriber_detail subscriberid | merchant_id 23 | 24 user_detail user_id | user_registeredid 23 | 1001001 24 | 1001002
need fetch user_registeredid
user_login
table subscriberid , merchant_id subscriber_detail
select sub.user_registeredid subscriberregisteredid, mer.user_registeredid merchantregisteredid subscriber_detail s join user_detail sub on s.subscriberid = sub.user_id join user_detail mer on s.merchant_id = mer.user_id
you need join both tables , table user_detail
should join 2 times because there 2 columns in table subscriber_detail
referenced it.
if 1 column nullable, left join
should used instead.
select sub.user_registeredid subscriberregisteredid, mer.user_registeredid merchantregisteredid subscriber_detail s left join user_detail sub on s.subscriberid = sub.user_id left join user_detail mer on s.merchant_id = mer.user_id
Comments
Post a Comment