Try select n.name, p.type, p.addr from p join name on p.id = n.id union select n.name, e.type, e.addr from e join name on e.id = n.id
Patty On Fri, May 15, 2009 at 12:14 AM, Evan Burkitt <ol2x6e...@sneakemail.com> wrote: > This isn't a Sqlite question per se, but I know there are some SQL gurus > here who might have some insight into this problem. I apologize for > being off-topic; I can be shameless when I need help. :)> > > I have three tables, N, P and E. N contains the fields id and name. The > other two each contain the fields id, type and addr. P holds phone > numbers, E email addresses. In P, the type field is always 'phone'; in > the P it is always 'email'. They are all related on id. > > I want to build a single query that will return a result set consisting > of N.name, P/E.type and P/E.addr. That is, it contains the like-named > fields of both P and E. For example: > > -name-------- -type--- -addr--------- > "John Smith", "phone", "123-555-1212" > "John Smith", "email", "john.sm...@domain.com" > "Bill Jones", "phone", "123-555-1213" > "Jane Johnson", "email", "j...@anotherdomain.com" > > and so forth. The order of the names and types is not important. > > Is this possible? > > -evan > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users