Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help w/ nested sql select??

Status
Not open for further replies.

imandy

Programmer
Feb 13, 2004
2
GB
Hi

I have the following mysql tables:

TRANSACTIONS
customerid int
item varchar
time datetime

What i want to do is select all similar items which have been bought within a time frame of say 2 hours.
the start and end time don't matter, just the difference.

i can do this with a SELECT item, time from transactions order by time;
( call this rs1 and var item1 = rs1.getString("item"), var time1 = rs1.getString("time") )
and then iterate over the resulset, but this is expensive.
i.e. SELECT item from transactions where item = item1 and time between time1 and (time1 + 2)

can i do this in a single sql expression?

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top