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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.