AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL subquery returns more than 1 row (1242) (https://forums.alliedmods.net/showthread.php?t=326030)

aim.dll 07-15-2020 17:36

SQL subquery returns more than 1 row (1242)
 
Hey guys.

What's wrong with this line?

SELECT a.name, (SELECT points FROM `rcsgo_player` WHERE name = a.name) as points, (SELECT rank FROM `csgo_ranks` WHERE name = a.name) as rank FROM `csgo_clans_applications` a WHERE clan = '%i' ORDER BY rank DESC, points DESC

gabuch2 07-15-2020 18:06

Re: SQL subquery returns more than 1 row (1242)
 
Subqueries need to be limited.

Bugsy 07-15-2020 19:08

Re: SQL subquery returns more than 1 row (1242)
 
Is the name field unique?

aim.dll 07-16-2020 00:53

Re: SQL subquery returns more than 1 row (1242)
 
What do you mean limited? So how to make this line right?

+ARUKARI- 07-16-2020 01:17

Re: SQL subquery returns more than 1 row (1242)
 
Unless you present the table layout, there is no answer.

gabuch2 07-16-2020 14:04

Re: SQL subquery returns more than 1 row (1242)
 
Quote:

Originally Posted by aim.dll (Post 2710292)
What do you mean limited? So how to make this line right?

Easiest way to "fix" it is to add LIMIT 1 at the end of your subqueries, but you need to verify why the subqueries are returning more than 1 row. If you let it slide it may result on unintended behaviour.

Bugsy 07-16-2020 17:46

Re: SQL subquery returns more than 1 row (1242)
 
You would not be able to trust the results if more than 1 record is returned since the data should be specific to 1 player so I do not recommend using the LIMIT 1 statement.

Instead of using name, use steam id as this field is unique to a player and you will only get 1 result.

Code:


SELECT csgo_clans_applications.name, rcsgo_player.points, csgo_ranks.rank

FROM (csgo_clans_applications

LEFT JOIN rcsgo_player
ON csgo_clans_applications.steamid = rcsgo_player.steamid)

LEFT JOIN csgo_ranks
ON csgo_clans_applications.steamid = csgo_ranks.steamid

WHERE clan = '%i'

ORDER BY rank DESC, points DESC



All times are GMT -4. The time now is 13:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.