views:

454

answers:

1

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.

A: 

Some things you could do:

  1. Ensure there is an index on sb_Selection(MeetingId, EventId, MarketId)
  2. Ensure there is an index on sb_Market(MeetingId, EventId, MarketId)
  3. Consider covering indexes if you need better performance (Eg. you could cover S.team, S.Status, S.PriceText)
Sam Saffron