Re: [sqlite] Conditional JOIN

2014-04-01 Thread Paul
> Apparently, SQLite always executes the join before evaluating other > conditions. > > Try something like this: > > SELECT * > FROM Big INNER JOIN Small ON Big.ID = Small.BigID > UNION ALL > SELECT *, NULL, NULL, ... > FROM Big > WHERE NOT flag > This is indeed a nice solution! But

Re: [sqlite] Conditional JOIN

2014-04-01 Thread Clemens Ladisch
Pavlo wrote: >> Pavlo wrote: >>> I want to lookup small tables only when flag is set but I can't see >>> how to tell SQLite to skip JOIN lookup for certain rows and return >>> NULLs. >> >> SELECT * FROM Big LEFT JOIN Small ON Big.flag AND Big.ID = Small.BigID > > Sadly, you are wrong here. >

Re: [sqlite] Conditional JOIN

2014-04-01 Thread Pavlo
Hey Clemens. Thank you for your reply! > Pavlo wrote: > > What I have is one big table storing all mandatory properties of an entity > > and several small tables, storing optional properties. > > > > So, when I need to select big number of elements using JOIN the probability > > of optional

Re: [sqlite] Conditional JOIN

2014-03-31 Thread Clemens Ladisch
Pavlo wrote: > What I have is one big table storing all mandatory properties of an entity > and several small tables, storing optional properties. > > So, when I need to select big number of elements using JOIN the probability > of optional properties is low. > And so, for every row from big

[sqlite] Conditional JOIN

2014-03-31 Thread Pavlo
Cheers. I love to use SQLite engine and I am performance paranoid. Today I had an idea how to optimize complex query with JOINs. What I have is one big table storing all mandatory properties of an entity and several small tables, storing optional properties. If for example big table may

Re: [sqlite] Conditional JOIN

2009-10-28 Thread Peter Haworth
Jay, First, yes I screwed up on the table data examples. The 3/SPECIAL TAbleA values should have shown 2 3/STANDARD TableB entries. My brain is hurting too! Anyway, the main thing is that your latest suggestion works perfectly so thanks for your help, I appreciate it. Pete On Oct

Re: [sqlite] Conditional JOIN

2009-10-27 Thread Jay A. Kreibich
On Tue, Oct 27, 2009 at 12:43:56PM -0700, Peter Haworth scratched on the wall: > It almost works but not quite. I believe that at least part of the > reason for this is that, as you commented, there can be multiple > entries in TableB that match any single ProdID/PriceTable in TableA.

Re: [sqlite] Conditional JOIN

2009-10-26 Thread Jay A. Kreibich
On Mon, Oct 26, 2009 at 05:32:27PM -0700, Peter Haworth scratched on the wall: > Looking for a way to implement the following situation > > I need to select entries form TableA and TableB. The join needs to > happen using two separate fields. One of this fields can be used in > the normal

Re: [sqlite] Conditional JOIN

2009-10-26 Thread Darren Duncan
You should be able to do what you want with a single SELECT. You are on the right track with trying to use UNION and EXCEPT. What you are trying to do can be accomplished with a generalization of an outer join. Try something like this pseudo-code, which uses common-table-expressions for

[sqlite] Conditional JOIN

2009-10-26 Thread Peter Haworth
Looking for a way to implement the following situation I need to select entries form TableA and TableB. The join needs to happen using two separate fields. One of this fields can be used in the normal way but the other filed needs some special logic The normal join field is ProdID and the