dbTalk Databases Forums  

Complex query - PLEASE HELP!

comp.databases comp.databases


Discuss Complex query - PLEASE HELP! in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
strawberry
 
Posts: n/a

Default Re: Complex query - PLEASE HELP! [Solved] - 02-05-2008 , 05:34 PM






On Feb 3, 1:39 am, "S." <sianeag... (AT) gmail (DOT) com> wrote:
Quote:
Thanks Thomas,

That was exactly what i was after!

S.
5 stars! For that! Too generous! ;-)

I think there must be a solution that doesn't require a subquery but
my brains a bit frazzled today. I think it could be something along
these lines, but I'd have to extend the dataset to be sure:

SELECT t1.*
FROM orders t1
LEFT JOIN orders t2
ON t1.customer = t2.customer
AND t1.orderdate < t2.orderdate
AND t2.orderdate < '2007-12-20'
WHERE t2.id IS NULL
HAVING orderdate < '2007-12-20';


Reply With Quote
  #12  
Old   
strawberry
 
Posts: n/a

Default Re: Complex query - PLEASE HELP! [Solved] - 02-05-2008 , 05:34 PM






On Feb 3, 1:39 am, "S." <sianeag... (AT) gmail (DOT) com> wrote:
Quote:
Thanks Thomas,

That was exactly what i was after!

S.
5 stars! For that! Too generous! ;-)

I think there must be a solution that doesn't require a subquery but
my brains a bit frazzled today. I think it could be something along
these lines, but I'd have to extend the dataset to be sure:

SELECT t1.*
FROM orders t1
LEFT JOIN orders t2
ON t1.customer = t2.customer
AND t1.orderdate < t2.orderdate
AND t2.orderdate < '2007-12-20'
WHERE t2.id IS NULL
HAVING orderdate < '2007-12-20';


Reply With Quote
  #13  
Old   
strawberry
 
Posts: n/a

Default Re: Complex query - PLEASE HELP! [Solved] - 02-05-2008 , 05:34 PM



On Feb 3, 1:39 am, "S." <sianeag... (AT) gmail (DOT) com> wrote:
Quote:
Thanks Thomas,

That was exactly what i was after!

S.
5 stars! For that! Too generous! ;-)

I think there must be a solution that doesn't require a subquery but
my brains a bit frazzled today. I think it could be something along
these lines, but I'd have to extend the dataset to be sure:

SELECT t1.*
FROM orders t1
LEFT JOIN orders t2
ON t1.customer = t2.customer
AND t1.orderdate < t2.orderdate
AND t2.orderdate < '2007-12-20'
WHERE t2.id IS NULL
HAVING orderdate < '2007-12-20';


Reply With Quote
  #14  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Complex query - PLEASE HELP! [Solved] - 02-05-2008 , 06:07 PM





strawberry wrote on 05.02.2008 23:34:
Quote:
On Feb 3, 1:39 am, "S." <sianeag... (AT) gmail (DOT) com> wrote:
Thanks Thomas,

That was exactly what i was after!

S.

5 stars! For that! Too generous! ;-)

I think there must be a solution that doesn't require a subquery but
my brains a bit frazzled today. I think it could be something along
these lines, but I'd have to extend the dataset to be sure:

SELECT t1.*
FROM orders t1
LEFT JOIN orders t2
ON t1.customer = t2.customer
AND t1.orderdate < t2.orderdate
AND t2.orderdate < '2007-12-20'
WHERE t2.id IS NULL
HAVING orderdate < '2007-12-20';
A subquery is not necessarily slower or less efficient than a join. But that
depends on the DBMS and the indexes available for the involved tables.

Tomas


Reply With Quote
  #15  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Complex query - PLEASE HELP! [Solved] - 02-05-2008 , 06:07 PM





strawberry wrote on 05.02.2008 23:34:
Quote:
On Feb 3, 1:39 am, "S." <sianeag... (AT) gmail (DOT) com> wrote:
Thanks Thomas,

That was exactly what i was after!

S.

5 stars! For that! Too generous! ;-)

I think there must be a solution that doesn't require a subquery but
my brains a bit frazzled today. I think it could be something along
these lines, but I'd have to extend the dataset to be sure:

SELECT t1.*
FROM orders t1
LEFT JOIN orders t2
ON t1.customer = t2.customer
AND t1.orderdate < t2.orderdate
AND t2.orderdate < '2007-12-20'
WHERE t2.id IS NULL
HAVING orderdate < '2007-12-20';
A subquery is not necessarily slower or less efficient than a join. But that
depends on the DBMS and the indexes available for the involved tables.

Tomas


Reply With Quote
  #16  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Complex query - PLEASE HELP! [Solved] - 02-05-2008 , 06:07 PM





strawberry wrote on 05.02.2008 23:34:
Quote:
On Feb 3, 1:39 am, "S." <sianeag... (AT) gmail (DOT) com> wrote:
Thanks Thomas,

That was exactly what i was after!

S.

5 stars! For that! Too generous! ;-)

I think there must be a solution that doesn't require a subquery but
my brains a bit frazzled today. I think it could be something along
these lines, but I'd have to extend the dataset to be sure:

SELECT t1.*
FROM orders t1
LEFT JOIN orders t2
ON t1.customer = t2.customer
AND t1.orderdate < t2.orderdate
AND t2.orderdate < '2007-12-20'
WHERE t2.id IS NULL
HAVING orderdate < '2007-12-20';
A subquery is not necessarily slower or less efficient than a join. But that
depends on the DBMS and the indexes available for the involved tables.

Tomas


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.