简体   繁体   中英

SQL What's wrong with my query

SELECT 'name'  FROM 'players' WHERE 'id' IN
    (SELECT 'player_id' from 'players_online' WHERE 'frags'=
    (SELECT MAX(frags) FROM 'players_online')) 
AND 'name' is not null LIMIT 1;

There are two tables, in second one there are important maximum of column called frags and i want to extract a name from table 1 where columns id and player_id have this same values. When i check it with no single quotes it works but i need to keep a quotes cause of lua script phraser return a bool expression not a string

Lua code:

BestPAl=db.storeQuery("SELECT name FROM players WHERE id IN(SELECT player_id from players_online WHERE frags=(SELECT MAX(frags) FROM players_online)) AND name is not null LIMIT 1;")
BestPA=result.getDataString(BestPAl)'code'

You don't need quotes for table and field names. Try it like this

SELECT name FROM players WHERE id IN(SELECT player_id from players_online WHERE frags=(SELECT MAX(frags) FROM players_online)) AND name is not null LIMIT 1;

Ok, result of this problem may look like a solution before:

local BestPAl=db.storeQuery("SELECT `player_id` FROM `players_online` ORDER BY `frags` DESC LIMIT 1")
local BestPA=result.getDataInt(BestPAl, "player_id")
result.free(BestPAl)
local BestPAm=db.storeQuery("SELECT `name` FROM `players` WHERE `id` = " .. BestPA )

I divided query into two, each of them is written to variable. Atention! this code in lua refers to own functions implemented in supported program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM