473,560 Members | 3,037 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 1967
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
2629
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...
1
1393
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
1188
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...
0
3410
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 |...
16
4163
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...
6
4829
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
1287
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
3795
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 ...
18
2283
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...
7
1685
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'...
0
7632
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...
0
7841
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8066
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7920
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...
0
5175
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...
0
3605
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2047
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

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.