Jump to content

select within select


decrease789

Recommended Posts

what i want to do is return a list of films which have consecutive ranks at and above a certain number (in this example 3) how the hell can i get select within select working??? it keeps giving me error 1064 so from table with [code]+----------------+------+
| name          | rank |
+----------------+------+
| Enfant, L'    |    1 |
| Grand bleu, Le |    2 |
| Magnolia      |    3 |
| Spider        |  999 |
| Rosetta        |    4 |
+----------------+------+[/code] i want[code]+----------------+------+
| name          | rank |
+----------------+------+
| Magnolia      |    3 |
| Rosetta        |    4 |
+----------------+------+[/code] im running MySQL 4.0.24. i want to perform this mysql query but it won't work[code]SET @rank = 1 ;
SELECT name, rank FROM (
SELECT name, rank FROM movies WHERE (@rank=rank-1 OR rank = 1) AND @rank:=rank
)
WHERE 3 <= rank;[/code]i tried this as an alternative[code] SET @rank = 1 ;
SELECT name, rank FROM movies WHERE (@rank=rank-1 OR rank = 1) AND @rank:=rank AND 3 <= rank;[/code]but it returns an empty set???? however it works for less than rather than greater than [code] SET @rank = 1 ;
SELECT name, rank FROM movies WHERE (@rank=rank-1 OR rank = 1) AND @rank:=rank AND 3 >= rank;[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.