Or you could do something really fancy.... https://en.wikipedia.org/wiki/Z-order_curve http://www.forceflow.be/2013/10/07/morton-encodingdecoding-through-bit-interleaving-implementations/
- (x,y,z) = *(5,9,1)* = (0101,1001,0001) - Interleaving the bits results in: 010001000111 = *1095* th cell along the Z-curve. doesn't have to be base 2 merging, could use base10 digits and merge them interleaving.... (a,b) = (123, 567) merged = 152637 Although for simpliicty simply combining them with a separator character would work too.... if you don't have a separator (1,111) would look the same as (111,1) On Fri, Oct 20, 2017 at 1:17 PM, Eugene Mirotin <emiro...@gmail.com> wrote: > Yeah, use two FKs, then you can obtain this "combined" value on select: > > select printf("%s-%s", student_id, workpiecelist_id) as id from > uniqueworkpc > > On Fri, Oct 20, 2017 at 11:05 PM David Raymond <david.raym...@tomtom.com> > wrote: > > > I don't know about automatically, but you can use foreign keys to help. > > > > create table student ( > > student_id integer primary key, > > blah > > ); > > create table workpiecelist ( > > workpiecelist_id integer primary key, > > blah > > ); > > > > create table uniqueworkpc ( > > student_id int references student, > > workpiecelist_id int references workpieceList, > > blah, > > primary key (student_id, workpiecelist_id) > > ); > > > > > > > > -----Original Message----- > > From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] > > On Behalf Of csanyipal > > Sent: Friday, October 20, 2017 3:57 PM > > To: sqlite-users@mailinglists.sqlite.org > > Subject: [sqlite] How to create primary key from two another PK's? > > > > Hi, > > > > I have a small and simple database MyStudents.db . > > It has three tables: *student*, *workpiecelist*, *uniqueworkpc*. > > How can I manage to get primary key (pk) automatically for *uniqueworkpc* > > table which is composed by pk of *student* table and pk of > *workpiecelist* > > table like below? > > 03256789415632-2 > > where > > 03256789415632 > > is a pk of a student in *student* table, and > > 2 > > is an id of a workpiece in *workpiecelist* table. > > > > > > > > ----- > > Best, Pál > > -- > > Sent from: http://sqlite.1065341.n5.nabble.com/ > > _______________________________________________ > > sqlite-users mailing list > > sqlite-users@mailinglists.sqlite.org > > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ > > sqlite-users mailing list > > sqlite-users@mailinglists.sqlite.org > > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users