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 に答える