Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
810 views
in Technique[技术] by (71.8m points)

drupal - Drupla 8 database query MAX(id)

I'm trying to run a query using the database api inside a form:

https://www.drupal.org/docs/8/api/database-api/dynamic-queries/introduction-to-dynamic-queries

$get_key = $this->connection->query("SELECT * FROM tablekeys WHERE id IN ( SELECT MAX(id) FROM tablekeys WHERE key = 'System' GROUP BY ip) ORDER BY id DESC");

The query returns my desired results.

The first select gets all fields and orders them by id desc.

The internal query selects the MAX(id) with where condition and groups the result by ip.

I have been trying to apply the API but it's throwing errors

$get_key = $this->connection->select('tablekeys', 'u')

->fields('u') Condition? ->condition('id', $another_db_cal?, 'IN') also the other db call ->fields('u', [MAX('id')])

Any help would be appreciated creating one db call or 2 dbs calls.

question from:https://stackoverflow.com/questions/65887924/drupla-8-database-query-maxid

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...