mysql Selecting from two different tables.

后端 未结 9 773
终归单人心
终归单人心 2021-01-28 05:01
$sql = \"select body, stamp from posts where user_id = \'$userid\' order by stamp desc\";

NOTE: the above query works fine. What I want to do is also s

9条回答
  •  盖世英雄少女心
    2021-01-28 06:06

    $sql = "SELECT p.body,p.stamp,u.username from posts p LEFT JOIN users as u ON (p.user_id = u.user_id) WHERE user_id = '$user_id' ORDER BY p.stamp DESC";
    

    should do it

提交回复
热议问题