|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help with Mysql query
ok i have three tables
post table ----------------- post_id --- category_id --- author_id -- content --- ect categories table ----------------- category_id --- category_name users table ------ author_id --- username --- pw whats the best way to query posts and fetch the related category_name and username with the post? how would i do it? should i do three separate select queries? or is there a better way? performance wise |
|
#2
|
||||
|
||||
|
JOINs are a wonderful thing. See http://sqlcourse2.com/joins.html
__________________
life is a game.... Have fun ----------------------------- http://www.phpwomen.org strength in unity PHPCommunity IRC #phpc on freenode |
|
#3
|
|||
|
|||
|
Quote:
SELECT post_id, content, category_name, username FROM tbl_post, tbl_category, tbl_users WHERE tbl_post.category_id = tbl_category.category_id AND tbl_post.author_id = tbl_users.author_id.. Should do the trick.... Last edited by leighrogers : April 10th, 2008 at 06:00 AM. Reason: tidy up |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Need help with Mysql query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|