2

db_select以下查询的等效查询是什么,

$nids = array(5, 3, 1, 4, 2);

$sql = "SELECT
          nid, title, FIELD(nid, :nids) sortkey
          FROM
            {node}
          WHERE
            nid IN (:nids)
            AND type = :type
            AND status = 1
          ORDER BY sortkey";

$result_nid = db_query($sql, array(':nids' => $nids, ':type' => 'article'))
                ->fetchAll();
4

1 回答 1

2

这是我从 drupal.org 获取的高级查询。

你应该很容易适应

$query = db_select('node', 'n');

$query->join('users', 'u', 'n.uid = u.uid'); //JOIN node with users

$query->groupBy('u.uid');//GROUP BY user ID

$query->fields('n',array('title','created'))//SELECT the fields from node
->fields('u',array('name'))//SELECT the fields from user
->orderBy('created', 'DESC')//ORDER BY created
->range(0,2);//LIMIT to 2 records

$result = $query->execute();

希望能帮助到你

公关

于 2012-11-19T20:46:37.510 回答