mardi 3 mai 2016

Writing a value from a row into the another row and column

I am trying to "marry" two imaginary people in my DB. What I want to do is select people within a certain age-range and then write each others IDs in a column.

If this is my table

ID | sex | age | married to
 1 | M   | 25  | NULL
 2 | F   | 28  | NULL
 3 | M   | 75  | NULL

The result should look something like this:

ID | sex  | age | married_to
 1 | M    | 25  | 2
 2 | F    | 28  | 1
 3 | M    | 75  | NULL

I know the select-statement should look something like this:

SELECT ID FROM table WHERE age BETWEEN ageMin AND ageMax AND married_to IS NULL

But I don't know how to get SQLite to write the ID in the right column. Espacially how to make this work in a DB with about 150k entries. For me the tricky part is to always just write into one row without having a super slow program. Could somebody help me out?

Aucun commentaire:

Enregistrer un commentaire