Unix Technical Forum

Query result very long, how do I enumerate displayed results?

This is a discussion on Query result very long, how do I enumerate displayed results? within the MySQL forums, part of the Database Server Software category; --> Let's say I have a list of 466 rows resulting from a query. How would I number the results ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:08 AM
Matchy
 
Posts: n/a
Default Query result very long, how do I enumerate displayed results?

Let's say I have a list of 466 rows resulting from a query. How would
I number the results so that I know exactly which item is # 220?
Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:08 AM
Paul Lautman
 
Posts: n/a
Default Re: Query result very long, how do I enumerate displayed results?

Matchy wrote:
> Let's say I have a list of 466 rows resulting from a query. How would
> I number the results so that I know exactly which item is # 220?
> Thanks.


SET @RNUM = 0;
SELECT @RNUM:=@RNUM+1 row_number, * FROM ...


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:08 AM
Matchy
 
Posts: n/a
Default Re: Query result very long, how do I enumerate displayed results?

On Sun, 11 Feb 2007 21:03:11 -0000, "Paul Lautman"
<paul.lautman@btinternet.com> wrote:

>Matchy wrote:
>> Let's say I have a list of 466 rows resulting from a query. How would
>> I number the results so that I know exactly which item is # 220?
>> Thanks.

>
>SET @RNUM = 0;
>SELECT @RNUM:=@RNUM+1 row_number, * FROM ...
>


I'm getting an error below using the test database 'world' available
from mysql.com? I'm using a mysql version for WinXP. What am I doing
wrong? Thanks!

--cut, cut--

mysql> use world;
Database changed
mysql> set @RNUM = 0;
Query OK, 0 rows affected (0.02 sec)

mysql> select @RNUM := @RNUM+1 row_number, * from city;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that
corresponds to your MySQL server version for the right syntax to use
near '* from city' at line 1
mysql> select * from city limit 5;
+----+----------------+-------------+---------------+------------+
| ID | Name | CountryCode | District | Population |
+----+----------------+-------------+---------------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
| 2 | Qandahar | AFG | Qandahar | 237500 |
| 3 | Herat | AFG | Herat | 186800 |
| 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
| 5 | Amsterdam | NLD | Noord-Holland | 731200 |
+----+----------------+-------------+---------------+------------+
5 rows in set (0.19 sec)

mysql> select version();
+---------------------+
| version() |
+---------------------+
| 5.0.27-community-nt |
+---------------------+
1 row in set (0.00 sec)

mysql> exit
Bye
$ pwd
/C/wamp/mysql/bin
$ uname -a
UWIN-XP XXXXXX 4.1.0/5.1 2600 i686
$ cmd
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\wamp\mysql\bin>exit
$
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:09 AM
Captain Paralytic
 
Posts: n/a
Default Re: Query result very long, how do I enumerate displayed results?

On 12 Feb, 16:48, Matchy <noaddr...@incaseitaintobvious.com> wrote:
> On Sun, 11 Feb 2007 21:03:11 -0000, "Paul Lautman"
>
> <paul.laut...@btinternet.com> wrote:
> >Matchy wrote:
> >> Let's say I have a list of 466 rows resulting from a query. How would
> >> I number the results so that I know exactly which item is # 220?
> >> Thanks.

>
> >SET @RNUM = 0;
> >SELECT @RNUM:=@RNUM+1 row_number, * FROM ...

>
> I'm getting an error below using the test database 'world' available
> from mysql.com? I'm using a mysql version for WinXP. What am I doing
> wrong? Thanks!
>
> --cut, cut--
>
> mysql> use world;
> Database changed
> mysql> set @RNUM = 0;
> Query OK, 0 rows affected (0.02 sec)
>
> mysql> select @RNUM := @RNUM+1 row_number, * from city;
> ERROR 1064 (42000): You have an error in your SQL syntax; check the
> manual that
> corresponds to your MySQL server version for the right syntax to use
> near '* from city' at line 1
> mysql> select * from city limit 5;
> +----+----------------+-------------+---------------+------------+
> | ID | Name | CountryCode | District | Population |
> +----+----------------+-------------+---------------+------------+
> | 1 | Kabul | AFG | Kabol | 1780000 |
> | 2 | Qandahar | AFG | Qandahar | 237500 |
> | 3 | Herat | AFG | Herat | 186800 |
> | 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
> | 5 | Amsterdam | NLD | Noord-Holland | 731200 |
> +----+----------------+-------------+---------------+------------+
> 5 rows in set (0.19 sec)
>
> mysql> select version();
> +---------------------+
> | version() |
> +---------------------+
> | 5.0.27-community-nt |
> +---------------------+
> 1 row in set (0.00 sec)
>
> mysql> exit
> Bye
> $ pwd
> /C/wamp/mysql/bin
> $ uname -a
> UWIN-XP XXXXXX 4.1.0/5.1 2600 i686
> $ cmd
> Microsoft Windows XP [Version 5.1.2600]
> (C) Copyright 1985-2001 Microsoft Corp.
>
> C:\wamp\mysql\bin>exit
> $


Try changing it to:
set @RNUM = 0;
select @RNUM := @RNUM+1 row_number, city.* from city;


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:09 AM
John C.
 
Posts: n/a
Default Re: Query result very long, how do I enumerate displayed results?

>
>Try changing it to:
>set @RNUM = 0;
>select @RNUM := @RNUM+1 row_number, city.* from city;


I tried this using the world database and I also unsuccessfully
checked mysql's ab faq, googled and gave up and still don't
understand why the row number starts at 4080 (note: I think there
there are a total of 4079 items). How does one make it (row_number)
start counting at 1? Thank you.

mysql> select @rnum:=@rnum+1 row_number, city.* from city limit 4;
+------------+----+----------------+-------------+----------+------------+
| row_number | ID | Name | CountryCode | District | Population |
+------------+----+----------------+-------------+----------+------------+
| 4080 | 1 | Kabul | AFG | Kabol | 1780000 |
| 4081 | 2 | Qandahar | AFG | Qandahar | 237500 |
| 4082 | 3 | Herat | AFG | Herat | 186800 |
| 4083 | 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
+------------+----+----------------+-------------+----------+------------+
4 rows in set (0.00 sec)

mysql> select city.* from city limit 4;
+----+----------------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+----------------+-------------+----------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
| 2 | Qandahar | AFG | Qandahar | 237500 |
| 3 | Herat | AFG | Herat | 186800 |
| 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
+----+----------------+-------------+----------+------------+
4 rows in set (0.00 sec)



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 09:09 AM
Captain Paralytic
 
Posts: n/a
Default Re: Query result very long, how do I enumerate displayed results?

On 14 Feb, 06:20, John C. <fakel...@fake.com> wrote:
> >Try changing it to:
> >set @RNUM = 0;
> >select @RNUM := @RNUM+1 row_number, city.* from city;

>
> I tried this using the world database and I also unsuccessfully
> checked mysql's ab faq, googled and gave up and still don't
> understand why the row number starts at 4080 (note: I think there
> there are a total of 4079 items). How does one make it (row_number)
> start counting at 1? Thank you.
>
> mysql> select @rnum:=@rnum+1 row_number, city.* from city limit 4;
> +------------+----+----------------+-------------+----------+------------+
> | row_number | ID | Name | CountryCode | District | Population |
> +------------+----+----------------+-------------+----------+------------+
> | 4080 | 1 | Kabul | AFG | Kabol | 1780000 |
> | 4081 | 2 | Qandahar | AFG | Qandahar | 237500 |
> | 4082 | 3 | Herat | AFG | Herat | 186800 |
> | 4083 | 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
> +------------+----+----------------+-------------+----------+------------+
> 4 rows in set (0.00 sec)
>
> mysql> select city.* from city limit 4;
> +----+----------------+-------------+----------+------------+
> | ID | Name | CountryCode | District | Population |
> +----+----------------+-------------+----------+------------+
> | 1 | Kabul | AFG | Kabol | 1780000 |
> | 2 | Qandahar | AFG | Qandahar | 237500 |
> | 3 | Herat | AFG | Herat | 186800 |
> | 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
> +----+----------------+-------------+----------+------------+
> 4 rows in set (0.00 sec)


Wierd,
I just tried
SET @RNUM =0;
SELECT @RNUM := @RNUM +1row_number, `pages` . *
FROM `pages` LIMIT 4
On a table with 18 records and the output was correctly numbered.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com