mercredi 1 juillet 2015

SQLite: query for all unique elements from multiple columns and multiple tables

I got an SQLite table similar to this one:

enter image description here

I'd like to perform a query that returns all unique user IDs in this table (i.e. all unique values over columns first_user_id, second_user_id and third_user_id). In the example above this query would return 1, 2, 3, 5, 6, 7.

I need this query to be efficient.

The second part of the question concerns the same functionality, but achieved over multiple columns from multiple tables. For example if I also have the following table:

enter image description here

I would like to know all unique values over columns first_user_id, second_user_id, third_user_id, first_owner_id, second_owner_id. For the two tables above this query would return 1, 2, 3, 4, 5, 6, 7

Thanks

Aucun commentaire:

Enregistrer un commentaire