mysql - Join query is going wrong -
i have 2 tables: first travellers_details
, second user_info
.
- traveller_details table has columns id,
travel_mode
,dep_from
,arr_to
,dep_date
,user_id
,status
. - user_info table has columns
user_id
,first_name
,last_name
,email
.
i want records of both table join user_id
, wrote following query not correct:
$sql="select * `traveller_details` full outer join `user_info` on traveller_details.user_id=user_info.user_id traveller_details.dep_from='".$this->from."' , traveller_details.arr_to='".$this->to."' , traveller_details.dep_date='".$this->sending_date."' , traveller_details.status='n'";
mysql doesn't support full outer join
, query doesn't work. suspect left join
sufficient:
select * `traveller_details` td left outer join `user_info` ui on td.user_id = ui.user_id td.dep_from = '".$this->from."' , td.arr_to = '".$this->to."' , td.dep_date = '".$this->sending_date."' , td.status = 'n'";
if travelers have valid user info, inner join
sufficient.
note table aliases make query easier write , read.
Comments
Post a Comment