Trying to speed up a SQLITE UNION QUERY

Posted by user142683 on Stack Overflow See other posts from Stack Overflow or by user142683
Published on 2009-07-22T10:15:32Z Indexed on 2010/04/08 10:03 UTC
Read the original article Hit count: 405

Filed under:
|
|
|

I have the below SQLITE code

SELECT x.t,
CASE WHEN S.Status='A' AND M.Nomorebets=0 THEN S.PriceText ELSE '-' END AS Show_Price
FROM sb_Market M
LEFT OUTER JOIN
(select 2010 t union
select 2020 t union
select 2030 t union
select 2040 t union
select 2050 t union
select 2060 t union
select 2070 t
) as x
LEFT OUTER JOIN sb_Selection S ON
S.MeetingId=M.MeetingId AND
S.EventId=M.EventId AND
S.MarketId=M.MarketId AND
x.t=S.team
WHERE M.meetingid=8051 AND M.eventid=3 AND M.Name='Correct Score'

With the current interface restrictions, I have to use the above code to ensure that if one selection is missing, that a '-' appears.

Some feed would be something like the following

SelectionId Name Team Status PriceText
===================================
1 Barney 2010 A 10
2 Jim 2020 A 5
3 Matt 2030 A 6
4 John 2040 A 8
5 Paul 2050 A 15/2
6 Frank 2060 S 10/11
7 Tom 2070 A 15

Is using the above SQL code the quickest & efficient??

Please advise of anything that could help. Messages with updates would be preferable.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sqlite