sql - Adding an autoincrement column to query results -


without creating temp table autoincrement column, how can add auto-incrementing field query result? example,

select ???, * mytable 

should result in:

1|* 2|* 3|* 

i think looking row numbers. try this:

select (select count(0)          supportcontacts t1          t1.id <= t2.id          ) 'row number', * supportcontacts t2 order id;  

example table:

╔════╦═════════╦═════════════════════╗ ║ id ║  type   ║       details       ║ ╠════╬═════════╬═════════════════════╣ ║  1 ║ email   ║ admin@sqlfiddle.com ║ ║  2 ║ twitter ║ @sqlfiddle          ║ ╚════╩═════════╩═════════════════════╝ 

result:

╔════════════╦════╦═════════╦═════════════════════╗ ║ row number ║ id ║  type   ║       details       ║ ╠════════════╬════╬═════════╬═════════════════════╣ ║          1 ║  1 ║ email   ║ admin@sqlfiddle.com ║ ║          2 ║  2 ║ twitter ║ @sqlfiddle          ║ ╚════════════╩════╩═════════╩═════════════════════╝ 

see sqlfiddle


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -