TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   join 3 table? (http://www.talkphp.com/mysql-databases/3695-join-3-table.html)

kokjj87 12-02-2008 02:47 PM

join 3 table?
 
Hi, to keep things simple I have 3 table..

user
id, username

blog
id, blog_post, user_id

blog_comment
id, blog_id

With blog_id in the blog_comment, i wan to retrieve the username, how do i do it?.. (I need the query string)

Thanks

xenon 12-02-2008 04:13 PM

Code:

SELECT u.*, b.*, bc.* FROM blog_comment bc LEFT JOIN blog b ON(b.id=bc.blog_id) LEFT JOIN user u ON(u.id=b.user_id)
That will return the result just fine, although it can be optimized.

KingOfTheSouth 12-02-2008 08:39 PM

Code:

$get = mysql_query("
                SELECT
                        nrank,pimp,hoes,thugs,guests,rating,thugskilled,hoeskilled,Pimp.worth,status,
                        Crew.icon
                FROM
                        $tab[pimp] Pimp LEFT OUTER JOIN
                        $tab[crew] Crew ON Pimp.crew = Crew.id
                WHERE
                        Pimp.rid='$round'
                ORDER BY
                        nrank ASC
                LIMIT 50;"
        );
  while ($usr = mysql_fetch_array($get)){

That is something I pulled some of my code Is that more of what you are looking for? A Query that is jointed?


All times are GMT. The time now is 11:15 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0