android - Sorting data from two different sorted cursors data of different tables into One -


i want sort results coming 2 cursors.

lets consider 2 cursors cursor1 , cursor2.

cursor1 used table x , cursor2 used table y.

cursor1 using column start of type date sort data , cursor2 using column date of type date sort data.

some fields common in both tables , not.

however, there no absolute relation between 2 tables.

the problem apparent. combined data should sorted list both cursors.

right what's happening is:

i getting sorted list cursor cursor1 independent of sorted list coming cursor cursor2.

how merge resulting cursors data in order sorted list both there dates (start , date) ?

for example:

i getting result:

| date                 | type        | location              | |:---------------------|------------:|:---------------------:| | 10-jul-2013 07:05:00 | random      | washougal, washington | 10-jul-2013 08:30:00 | single      | vancouver, washington | 10-jul-2013 07:30:00 | multiple    | vancouver, washington | 10-jul-2013 15:31:00 | double      | vancouver, washington 

where first 2 rows table x , last 2 rows table y in above result.

but want result:

| date                 | type        | location              | |:---------------------|------------:|:---------------------:| | 10-jul-2013 07:05:00 | random      | washougal, washington | 10-jul-2013 07:30:00 | multiple    | vancouver, washington | 10-jul-2013 08:30:00 | single      | vancouver, washington | 10-jul-2013 15:31:00 | double      | vancouver, washington 

queries should be:

cursor1 = select alpha, beeta, gamma, remark, id, number x order start asc   cursor2 = select type, date, gamma, location, obs, number y order date asc 

after getting result cursor1, making string html in loop this:

string itemlist = "";  itemlist += "<tr><td align='left' width='28%' style='font-size:8px;padding-left: 15px'>"     + cursor1.getstring(1)     + "</td><td width='16%' style='font-size:8px'>"     + cursor1.getstring(0)     + "</td><td width='10%' style='font-size:8px'>"     + cursor1.getstring(2)     + "</td><td width='20%' style='font-size:8px'>"      + "</td><td width='35%'>" + cursor1.getstring(3) + "</td></tr>"; 

then itemlist further added result cursor2 complete itemlist both cursors.

the final itemlist shown html in layout.

you combine both queries single query.

first, ensure both results have same number of columns. if not, might need add dummy column(s) 1 query.

then combine 2 union all:

select alpha, beeta, gamma, remark, id,   number x union select type,  date,  gamma, obs,    null, number y 

then pick 1 column of entire result want order by. (the column names of result come first query.) in case, start column not part of result, have add (and date column duplicated in second query, necessary values end in result column used sorting):

select alpha, beeta, gamma, remark, id,   number, start sortthis x union select type,  date,  gamma, obs,    null, number, date              y order sortthis 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -