SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to fake an index in a result set?

    I'm querying a table that does not have an index and the javascript grid I use requires an index for some reason. What's the easiest way to just return an incrementing value in one of the columns of the result set?

    Code:
    SELECT 
       [function to create incrementing value for each record] as id
       , name
       , email 
    FROM users 
    ORDER BY name

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I may have answered my own question. This seems to work:

    Code:
    SET @rowcount =0;
    SELECT 
       @rowcount := @rowcount +1 AS id
       , name
       , email 
    FROM users 
    ORDER BY name

  3. #3
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That isn't an index. I think you mean a counter.

    An index applies to a certain column or group of columns and relates to speeding searches on that column or group of columns.

    Don't want you or others to confuse the terminology.


Bookmarks

Posting Permissions

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