sqlite - Help Building SQL query -
i have following 2 tables
channels: id int pk title varchar subchannels: channelid int subchannelid int
when receive data service i'm trying persist sql. receive few channel instance, store in channels table, after i'm trying persist every subchannel (every channel contains list of subchannels), so, store subchannels in same table channels, , store theirs ids subchannel table in following way: channelid - subchannelid.
so, need tree of channels 1 query i'm trying this query:
select * channels except select channels.id, channels.title channels inner join subchannels on channels.id = subchannels.subchannelid
but doesn't work correctly. using mssql works fine, in sqlite going wrong.
could please me query, or advice me other solution store tree in sql.
my channel class looks this:
int id string title list<channel> subchannels
thanks in advance
could try:
select id, title channels except select channels.id, channels.title channels inner join subchannels on channels.id = subchannels.subchannelid
(ie, not selecting *
)
a way optimize it:
select id, title channels id not in ( select distinct subchannelid subchannels )
Comments
Post a Comment