jaiffed Posted February 18, 2010 Share Posted February 18, 2010 how can i select multiple fields from multiple table in one query like i have table name t1 and t2 t1 fields are f_id,f_name,f_des t2 fields are f_id,ft_name,ft_des i need query which select f_id from both tables and f_name from table t1 where table t2 f_des=1 plz help me Link to comment https://forums.phpfreaks.com/topic/192542-mysql-select-query-problem/ Share on other sites More sharing options...
The Little Guy Posted February 18, 2010 Share Posted February 18, 2010 Try this: SELECT * FROM t1 LEFT JOIN t2 ON (ft_des = f_des) WHERE f_des = 1 Link to comment https://forums.phpfreaks.com/topic/192542-mysql-select-query-problem/#findComment-1014444 Share on other sites More sharing options...
jaiffed Posted February 18, 2010 Author Share Posted February 18, 2010 what is left join and its not working and only f_id which are similar in both tables like f_id from t1 has 101,102,103, 104,105 and f_id from t2 has 101,103,104 now i need ids only 101,103,104 with their f_name from t2 Link to comment https://forums.phpfreaks.com/topic/192542-mysql-select-query-problem/#findComment-1014453 Share on other sites More sharing options...
phobucket Posted February 18, 2010 Share Posted February 18, 2010 If you only want records from t1 that have a matching record in t2 then try this: SELECT t1.f_id, t2.f_id, t1.f_name FROM t1 JOIN t2 ON t1.f_id = t2.f_id WHERE t2.f_des = 1; If you want all records from t1 whether or not there is a matching record on t2 with f_des = 1, then try this: SELECT t1.f_id, t2.f_id, t1.f_name FROM t1 LEFT JOIN t2 ON (t1.f_id = t2.f_id AND t2.f_des = 1); Link to comment https://forums.phpfreaks.com/topic/192542-mysql-select-query-problem/#findComment-1014491 Share on other sites More sharing options...
jaiffed Posted February 18, 2010 Author Share Posted February 18, 2010 Thanks photobucket it's working perfectly Link to comment https://forums.phpfreaks.com/topic/192542-mysql-select-query-problem/#findComment-1014556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.