using joins or multiple queries in php/mysql
Posted
by askkirati
on Stack Overflow
See other posts from Stack Overflow
or by askkirati
Published on 2010-05-03T12:12:12Z
Indexed on
2010/05/03
12:18 UTC
Read the original article
Hit count: 376
Here i need help with joins. I have two tables say articles and users. while displaying articles i need to display also the user info like username, etc. So will it be better if i just use joins to join the articles and user tables to fetch the user info while displaying articles like below.
SELECT a.*,u.username,u.id FROM articles a JOIN users u ON u.id=a.user_id
OR can this one in php. First i get the articles with below sql
SELECT * FROM articles
Then after i get the articles array i loop though it and get the user info inside each loop like below
SELECT username, id FROM users WHERE id='".$articles->user_id."';
Which is better can i have explanation on why too. Thank you for any reply or views
© Stack Overflow or respective owner