Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete rows with inner join?

I have a SQLITE database with two tables. Table A has an integer timestamp and another integer column containing a row id referring to a row in table B which has two timestamps.

I want to delete all rows in table A where it's timestamp does not lie between the two timestamps in table B, and the ROWID is equal to X.

Here is what I have at the moment but I am getting a syntax error:

DELETE FROM network
WHERE ROWID in (
    SELECT ROWID 
    FROM track 
    INNER JOIN network ON (track.ROWID = network.trackId) 
    WHERE network.timestamp > track.stopTime OR network.timestamp < track.startTime 
        AND network.trackId = X
like image 569
Max Mumford Avatar asked Dec 03 '11 00:12

Max Mumford


1 Answers

You don't have a closing parenthesis for your subselect. Try this:

DELETE FROM network
WHERE ROWID in (
    SELECT ROWID 
    FROM track 
    INNER JOIN network ON (track.ROWID = network.trackId) 
    WHERE network.timestamp > track.stopTime OR network.timestamp < track.startTime 
       AND network.trackId = X
)

If that doesn't work, try posting your actual syntax error.

like image 68
Flimzy Avatar answered Oct 19 '22 06:10

Flimzy