473,408 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

query within query

Hello,

I have a query that I've gotten to work fine in SQL Server, but when I
tried to run the same query on an indentially structured database in
MySQL, I get a syntax error. This is the query:

select user_id, score, (select count(*) + 1
from ericTest
where score > A.score) as rank from ericTest A

Essentially, it's a table of user_id, score, and the user's rank,
which is calculated by the inner query. Thoughts on what's wrong?

Thanks!

~ Eric
Jul 20 '05 #1
2 1960
Eric wrote:
select user_id, score, (select count(*) + 1
from ericTest
where score > A.score) as rank from ericTest A


Subqueries are supported from MySQL version 4.1 so I'm assuming you are
using older version of MySQL server.
Jul 20 '05 #2
Eric wrote:
I have a query that I've gotten to work fine in SQL Server, but when I
tried to run the same query on an indentially structured database in
MySQL, I get a syntax error. This is the query:

select user_id, score, (select count(*) + 1
from ericTest
where score > A.score) as rank from ericTest A

Essentially, it's a table of user_id, score, and the user's rank,
which is calculated by the inner query. Thoughts on what's wrong?


As Aggro pointed out, MySQL only supports subqueries as of version 4.1,
which just this week has been released out of beta/gamma status (hooray!).

Try this as an alternative that uses no subquerie:

SELECT A.user_id, A.score, COUNT(B.score) + 1 AS rank
FROM ericTest A LEFT OUTER JOIN ericTest B ON (B.score > A.score)
GROUP BY A.user_id

Regards,
Bill K.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: plato | last post by:
I'm an end user of a siebel program and i want to get some info on questions relating to queries within the program. Who or where can I get some answers beyond basic query operators? Maybe I...
1
by: maxmarengo | last post by:
I am trying to write a query in Access (or SQL) that works on a table like this: Location Gridreference Ben Nevis NQ1234512345 Ben Doon NQ1230012300 and so on for several thousand...
0
by: hismail | last post by:
I am creating a vb.net service that will run AS SERVICE. There is actually a timer; so the timer will run every 2 minutes and see if there are any new ERROR type logs in the APPLICATION logs. And...
0
by: hismail | last post by:
1. hism...@dot-solution.net Aug 16, 2:51 pm show options Newsgroups: microsoft.public.vb.general.discussion From: hism...@dot-solution.net - Find messages by this author Date: 16 Aug 2005...
16
by: tyrfboard | last post by:
I've been searching for awhile now on how to remove duplicates from a table within an Access db and have found plenty of articles on finding or deleting duplicates. All I want to do is remove them...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
1
by: Xeth Waxman | last post by:
Good afternoon, I have a bizarre question. When running the following query: select SomeColumnName from TableA where PK_TableA in (select PK_TableA from TableB) I get results. This should...
6
by: sara | last post by:
I hope someone can help with this. Our director wants to have a report that will have the departments (Retail stores) across the top, stores down the side and the RANKING of the YTD dept sales...
18
by: cov | last post by:
I have a query where I'm attempting to pull data from 3 different tables using php and mysql. I had hoped to have a unique identifier to help ensure referential integrity but it appears that...
7
by: cov | last post by:
I have a php query where I'm attempting to pull data from 3 different tables between a php form and mysql db. I had hoped early on to use a unique identifier to help ensure referential integrity...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.