Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...