www.webdeveloper.com
Results 1 to 2 of 2

Thread: MySQL: Getting the record number?

  1. #1
    Join Date
    Sep 2006
    Posts
    655

    Question MySQL: Getting the record number?

    Hi

    Suppose I have a query:

    Code:
    SELECT * FROM users ORDER BY user_id DESC
    and this returns 300 rows.

    What I want to know is, is it possible (in MYSQL) to know whats the record number for the user_id 50?


    I know I can run a loop in my php script and start a counter and get the record number with simple if() condition, but if there are 8000 records in my table, I dont want to iterate thru all the 8000 records...hence looking for an efficient SQL Query.


    Pls Help
    Thanks
    Last edited by phantom007; 04-09-2012 at 04:36 AM.

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Does the table have a column for the id of each record in the table? If so, then you can just access that by querying the query (ie, SELECT * FROM [queryName] WHERE user_id = 50). Depending upon what scripting language you're using. I know it can be done in ColdFusion. Not sure about anything else.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles