0

Let say here is my query

  SELECT id as people_ID FROM user
    UNION 
  SELECT id as people_ID FROM client

What I want is give every row a unique ID that will increment by adding new column as below:

+------+-------------+
|  ID  |  people_ID  |
+------+-------------+
|  1   |    Alex     |
+------+-------------+
|  2   |   Kenny     |
+------+-------------+
|  3   |   David     |
+------+-------------+
|  4   |  Ashley     |
+------+-------------+

Is it possible to accomplish it?

user3651999
  • 103
  • 1
  • 3
  • 7
  • Shouldn't that be `SELECT id AS people_ID FROM user`? – gen_Eric Dec 03 '14 at 17:49
  • 3
    you could try `set id=0; select @id := @id + 1 from user ... union select @id:=@id+1 from client` But there's no guarantee as to which order the subqueries would execute and return data. – Marc B Dec 03 '14 at 17:49
  • possible duplicate of [MySQL query: Using UNION and getting row number as part of SELECT](http://stackoverflow.com/questions/6122440/mysql-query-using-union-and-getting-row-number-as-part-of-select) – Anil Dec 03 '14 at 17:51

1 Answers1

0

Depends which database you use but you could probably do it with rowid as a first column

Sheremet
  • 32
  • 3