mysql - How to join 3 tables or more in one msql query -


normally make this.

#1 first query  while () :     #2 2nd queries     #3 3rd queries  endwhile; 

to result. want combine them in 1 query. how can done this.

table#1 ------------------------------------------- select  userid, username, countrycode, statecode, citycode, villagecode, userrace, userstatus, updatestatus  user_locality countrycode = '{$getcountrycode}'  table#2 ------------------------------------------- select  *  user_addresses  address_userid = '{$userid}'  table#3 ------------------------------------------- select  phone_userid, phone_m, phone_h, phone_o  user_phones  phone_userid  = '{$userid}' 

thank you.

you'll want use join clause. there different types of joins. i'm using left join below select records user_locality , try match records both user_addresses , user_phones.

select    *      `user_locality` left join `user_addresses` on        `user_addresses`.`address_userid` = `user_locality`.`userid` left join `user_phones` on        `user_phones`.`phone_userid` = `user_locality`.`userid`     `user_locality`.`countrycode` = '{$getcountrycode}' 

the 1 thing point out query result in more 1 row each user has more 1 phone or address.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -