Jump to content

SQL query for MySQL - running a query on a row against another row


suprsnipes

Recommended Posts

This is the SQL query. I'm not having a problem with this, but it's the steps afterwards, firstly let me explain what I am trying to do.

 

CREATE TABLE t3 AS (SELECT * FROM t1 INNER JOIN t2 on t1.id=t2.id-1)

 

id-1 represents the previous row (entry), id is set to auto_increment.

 

What you can see from this is I that am joining these two tables together so that I can compare the row of data prior. Whilst this query works this is my problem.

 

I would like to know if there is a better way to do this because I may need to run a query from id to perhaps id-20.

otherwise I need to perform the query above many, many times.

 

By the way once I have joined the tables the query I need to run is as follows;

 

SELECT * FROM t3 WHERE column1=a AND column2<=column3

 

Appreciate the help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.