如何从2个mysql表中获得结果?

时间:2014-02-03 18:55:18

标签: php mysql sql pdo

我希望得到2个表'altitle'和'scroll100'的结果,其中live = 1 delete = 0和kategori = 1或9或30.我实际上必须从一个表中得到任何人可以帮助我吗?< / p>

$results = $pdo->query('SELECT * FROM  `altitle` WHERE  `live` = 1 AND `delete` = 0 AND `kategori` = 1 ORDER BY  `id` DESC ')->fetchAll(PDO::FETCH_ASSOC);

1 个答案:

答案 0 :(得分:2)

关于你的评论,你应该把你的两个表放在FROM子句中:

$results = $pdo->query('SELECT * FROM  `altitle` a, `scroll100` s 
                        WHERE  a.`live` = 1
                        AND a.`delete` = 0 
                        AND (a.`kategori` = 1
                        OR a.`kategori` = 9
                        OR a.`kategori` = 30)
                        AND s.`live` = 1
                        AND s.`delete` = 0 
                        AND (s.`kategori` = 1
                        OR s.`kategori` = 9
                        OR s.`kategori` = 30)
                        ORDER BY  a.`id` DESC ')->fetchAll(PDO::FETCH_ASSOC);

这是一个奇怪的架构,你知道。