473,699 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1974
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
2641
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 should be more specific in case someone here knows. The siebel 7 program has screen tabs which i guess you can say is the parent program e.g. plans then there is a list applet and some view tabs under which is a form applet. The highlighted list...
1
1396
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 records. I have a function that calculates the distance between two points. What I want to do is write a query that will list for each point in
0
1189
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 if there are then it will send an email to me ( or whoever I want to specify). The thing that I can not figure out is how do I create the query so it queries only thing in the past 2 minutes. If I take the TimeWritten out of my query it works...
0
3412
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 11:51:51 -0700 Local: Tues, Aug 16 2005 2:51 pm Subject: Query Eventlog by Timewritten field. Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse
16
4177
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 from within an SQL query - leaving one of the records behind of course. I have a mailing list comprised of a union query that gets records from two separate tables. I want to be able to run a query that removes one (or more) of the duplicated...
6
4843
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 SalesManName AT Alan Time
1
1290
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 not be feasible, because the query within the in clause:
6
3805
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 within the chain in the cell. Store/Dept 1 2 3 4 B 8 1 5 2 R 1 3 2 6 (etc.)
18
2294
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 unique number won't always be a possibility so I won't bank on it at all. I have two like fields in these two tables 'area' and 'equipment' and though there is a possibility of having two different pieces of equipment within two areas called by the...
7
1693
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 between table data but it appears that unique number isn't viable so I going a different route. I have two similar columns in these tables 'area' and 'equipment' that I'd like to use as the unique identifier (when used together ) since though...
0
8697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8622
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8892
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7767
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3062
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.