MySQL: Include arbitrary count in SELECT

Recently I had some data that I needed to add an arbitrary count column to. MySQL lets you use user defined variables in your queries to augment your output. Here is an example that I ended up using to add a sequence number to a CSV I was generating.

set @num := 10;
SELECT First, Last, @num := @num+1 AS SequencNumber FROM CustInfo c;
Leave A Reply
All content licensed under the Creative Commons License