Got these 2 queries:
select d1.field_id_41 program_code, d1.field_id_48 program_group_code, t1.title program_lookup, t2.title group_title,
t1.url_title program_url_title, t2.url_title program_group_url_title
from channel_titles t1
join channel_data d1 on t1.entry_id = d1.entry_id
join channel_data d2 on d1.field_id_48 = d2.field_id_47
join channel_titles t2 on t2.entry_id = d2.entry_id
where t1.channel_id = 26 and d1.field_id_41 != ''
order by d2.field_id_45 , d1.field_id_9
select ProgramCode, ProgramGroup, EventCode, FormalDate, LocCity, LocState, LocAddress, LocName, Price,
zl.latitude as LocLatitude, zl.longitude as LocLongitude
from course_events e
join channel_data d on e.ProgramCode = d.field_id_41
join channel_titles t on d.entry_id = t.entry_id
join zip_lat_long zl on zl.zip = e.LocZipCode
Currently, the first query is used to populate three JSON objects called program_lookup, program_url_titles and program_group_url_titles.
And then items returned from the second query, also placed in a JSON object called event, are iterated and then portions of the results are shown in my HTML along with items from the lookup caches based on data in the events JSON object like this:
html = html + hr + '<div class="course"><div class="col1' + tm10 + '"><h4>' + program_lookup[event['ProgramCode']] + '</h4></div>';
html = html + '<div class="col1"><b>' + event['LocCity'] + '</b><br/>' + '... <a href="/courses/' + program_group_url_titles[event['ProgramGroup']] + '/'+ program_url_titles[event['ProgramCode']]+ '/' + event['EventCode'] + '" target="_new">View Details</a></div><div class="col2">';
I need to combine these into one query to get rid of the three lookup objects but am unsure if it would be very efficient or really how to go about doing this.
What this is going to allow me to do is use this utility, http://jsonselect.org, to basically filter items before they are shown in my HTML.
The reason why I need this is that I need to show certain items before all the others and placing them in the correct order cannot be done in the SQL.
Those select statements don’t match, so combining them is probably not what you want to do. One example of where you could combine two select statements would be a union all where your select clause matches:
You should add more detail about your client side requirements, but you can always combine multiple objects into a JSON object as follows. Let’s say you had 2 objects:
You could merge them into 1:
You can understand JSON as a simple object notation if you carefully read the first three diagrams on the official json page: http://www.json.org/