(Aug-24-2017, 04:15 PM)nilamo Wrote:(Aug-19-2017, 05:49 PM)chris0147 Wrote: If there is no null data above of the value 3021 in the same rows as the channel ITV then I won't do something.
"above" doesn't make sense in this context. The table doesn't have a primary key (...apparently), so the rows are unordered. The fact that they happen to look like they're ordered in whatever order they were inserted is an implementation detail, and isn't guaranteed to stay that way (ie: if you rebuild an index, the ordering could change).
It sort of looks like you want to do
select @row_id=row_id from {tablename} where program_id is null and channel = ? order by row_id desc limit 1; update set program_id = ? where row_id = @row_idBut without having a sequential id, any solution would look pretty hackish.
Maybe the best solution would be to alter the table and add a unique, auto-generated, primary key?
I'm sorry but I'm trying my best to explain what I am trying to achieved. I wanted to check if the row before the
3001
is empty or not so I could do something.However, I have found the solution. Here is what I use to check if the row before the
3001
is empty or not:conn = database.connect(profilePath) cur = conn.cursor() cur.execute("SELECT channel, start_date FROM programs WHERE program_id=?;",(program_id,)) data = cur.fetchone() cur.execute("SELECT channel FROM programs WHERE channel=? and stop_date=? ",(data[0],data[1])) data = cur.fetchone() cur.execute('SELECT start_date, stop_date, title FROM programs where program_id=?', [program_id]) data = cur.fetchone() #if data: if data is not None: print "you are working on this........." print data else: print "there is no empty row before that data so you don't need to do anything..."