Raised This Month: $32 Target: $400
 8% 

SQL subquery returns more than 1 row (1242)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aim.dll
Junior Member
Join Date: Jul 2017
Old 07-15-2020 , 17:36   SQL subquery returns more than 1 row (1242)
Reply With Quote #1

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

Last edited by aim.dll; 07-15-2020 at 17:37.
aim.dll is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 07-15-2020 , 18:06   Re: SQL subquery returns more than 1 row (1242)
Reply With Quote #2

Subqueries need to be limited.
__________________
gabuch2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2020 , 19:08   Re: SQL subquery returns more than 1 row (1242)
Reply With Quote #3

Is the name field unique?
__________________
Bugsy is offline
aim.dll
Junior Member
Join Date: Jul 2017
Old 07-16-2020 , 00:53   Re: SQL subquery returns more than 1 row (1242)
Reply With Quote #4

What do you mean limited? So how to make this line right?
aim.dll is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 07-16-2020 , 01:17   Re: SQL subquery returns more than 1 row (1242)
Reply With Quote #5

Unless you present the table layout, there is no answer.
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 07-16-2020 , 14:04   Re: SQL subquery returns more than 1 row (1242)
Reply With Quote #6

Quote:
Originally Posted by aim.dll View Post
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.
__________________

Last edited by gabuch2; 07-16-2020 at 14:04.
gabuch2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-16-2020 , 17:46   Re: SQL subquery returns more than 1 row (1242)
Reply With Quote #7

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
__________________

Last edited by Bugsy; 07-16-2020 at 21:43.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:46.


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