Reputation: 402
i am trying to fetch value from two tables of mysql database with same column name.now i am in trouble to specify column,means in two tables i have same column named contact_name.I have to contact name from both tables.i can't understand how can i identify that contact name come from which table..please help.
My query is
$wpdb->get_results( "SELECT * FROM tbl_ratings,tbl_providers,tbl_members where tbl_ratings.provider_id=tbl_providers.provider_id and tbl_ratings.member_id=tbl_members.member_id" );
In both tbl_providers and tbl_members i have to fetch contact name saperatly.thanx in advance.
Upvotes: 1
Views: 551
Reputation: 499
Oherwise use code like this...
$result ="SELECT $wpdb->posts.* FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) WHERE $wpdb->postmeta.meta_key = 'paragraf' AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' AND $wpdb->post2cat.category_id IN (1,2,3) ORDER BY $wpdb->postmeta.meta_value ASC";
Upvotes: 1
Reputation: 4621
use alias
with an example as i don't have your column name
For example if you have two table with one column id having same name
use
$sql = "Select first_table.id as id1 , second_table.id as id2 from first_table,second_table";
the above query when executed will return first_table id with name id1 & second_table id with name id2
Upvotes: 1