Normally I make something like this.
#1 first query
while () :
#2 2nd queries
#3 3rd queries
endwhile;
to get a result. Now I want to combine them in one query. How can be done with this.
Table#1
-------------------------------------------
SELECT
UserID, UserName, CountryCode, StateCode, CityCode, VillageCode, UserRace, UserStatus, UpdateStatus
FROM user_locality
WHERE CountryCode = '{$getCountryCode}'
Table#2
-------------------------------------------
SELECT
*
FROM user_addresses
WHERE address_UserID = '{$UserID}'
Table#3
-------------------------------------------
SELECT
phone_UserID, phone_m, phone_h, phone_o
FROM user_phones
WHERE phone_UserID = '{$UserID}'
Thank you.
You’ll want to use the
JOINclause. There are different types of joins. I’m usingLEFT JOINbelow which will select all records fromuser_localityand try to match records from bothuser_addressesanduser_phones.The one thing to point out this query will result in more than 1 row for each user that has more than 1 phone or address.