I have a query like this:
SELECT ordIdent.Identifier, ord.OrderId FROM OrderIdentifier ordIdent JOIN [order] ord ON ordIdent.OrderId = ord.OrderId WHERE ordIdent.Identifier = '29584' OR ord.ClientOrderId = '29584'
The idea is that we are searching using the value ‘29584’ and we don’t really know if it is a
ClientOrderId or an
Identifier, so we want to search both.
This gives really really bad performance. It pulls millions of rows (125 thousand from one and 20 Million from the other)
But this query:
SELECT ordIdent.Identifier, ord.OrderId FROM OrderIdentifier ordIdent JOIN [order] ord ON ordIdent.OrderId = ord.OrderId WHERE ord.ClientOrderId = '01193504' UNION SELECT ordIdent.Identifier, ord.OrderId FROM OrderIdentifier ordIdent JOIN [order] ord ON ordIdent.OrderId = ord.OrderId WHERE ordIdent.Identifier = '01193504'
has good performance. Normally I would just do this and call it a day.
But my actual query is very large, and I would rather not call it twice (though it is still better than using the “or”.) So before I just set it up to be called twice, I thought I would ask around and see if I have other options.
It seems I should be to do some kind of left join to make this work. But I can’t seem to wrap my head around it.
Is there a way to do this in one query that has a left join instead of an “OR”? (Or some other kind of option?)
OK, I got thinking about it and I realized I could just factor out the OR into a CTE that uses the
union and then use the CTE the actual query.
I will leave this open in case there is a better way to deal with it, but a CTE fixes my issue.
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!