drupal7用手动sql获取内容

时间:2022-08-14 22:11:46

Im trying to get all the articles from the drupal7 table using manual sql method, I am trying to use the tables named field_data_body, node, file_usage, file_managed. What I really want is something like this:

我试图使用手动sql方法从drupal7表中获取所有文章,我试图使用名为field_data_body,node,file_usage,file_managed的表。我真正想要的是这样的:

body_value | body_summary | nid | title | created_time | uri

I used the following sql code:

我使用了以下sql代码:

SELECT distinct body.body_value, body.body_summary, node.nid, node.title, FROM_UNIXTIME(node.created) as created, file_managed.uri
            FROM 
                node 
                    INNER JOIN field_data_body as body ON node.nid = body.entity_id
                    INNER JOIN file_managed ON file_usage.fid = file_managed.fid
            WHERE body.entity_id = node.nid
                AND node.type = 'article'
                AND node.status = '1'
            GROUP BY node.nid
            ORDER BY node.nid desc

it worked but I got only those articles that has an image with it and all the rest got ignored. Can someone suggest me on how to deal with these sql conditions?

它有效,但我只得到那些带有图像的文章,其余的都被忽略了。有人可以建议我如何处理这些SQL条件?

1 个解决方案

#1


0  

SELECT
  b.body_value,
  b.body_summary,
  n.nid,
  n.title,
  n.created,
  fm.uri
FROM
node n
LEFT JOIN field_data_body AS b ON n.nid = b.entity_id
LEFT JOIN file_usage AS fu ON fu.id = n.nid
LEFT JOIN file_managed AS fm ON fm.fid = fu.fid
WHERE n.type = 'article'
  AND n.status = '1'
GROUP BY n.nid
ORDER BY n.nid DESC;

#1


0  

SELECT
  b.body_value,
  b.body_summary,
  n.nid,
  n.title,
  n.created,
  fm.uri
FROM
node n
LEFT JOIN field_data_body AS b ON n.nid = b.entity_id
LEFT JOIN file_usage AS fu ON fu.id = n.nid
LEFT JOIN file_managed AS fm ON fm.fid = fu.fid
WHERE n.type = 'article'
  AND n.status = '1'
GROUP BY n.nid
ORDER BY n.nid DESC;