Jump to content

mysql select query problem


jaiffed

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.