V
V
ValeraValera2017-07-31 14:51:24
PHP
ValeraValera, 2017-07-31 14:51:24

How to write an SQL query, searching for the maximum match with a value?

There are two tables :
wp_konkurs_bets
E2pBk5Eu9MWLRr.png
wp_konkurs
xAevelgfpxQEMr.png
Need among all wp_konkurs records to find the id whose user_bet field matches the bet_val field value in the wp_konkurs table as much as possible and the user_time time is the earliest , how to write such a query ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-07-31
@Rsa97

ORDER BY ABS(`wp_konkurs`.`user_bet` - `wp_konkurs_bets`.`bet_val`), `user_time`
LIMIT 1

Only it is not clear on what fields the tables are connected.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question