************************************************** ******************************
************************************************** ******************************
SOLVED!
************************************************** ******************************
************************************************** ******************************
I will paypal you $20 within the day (hour if Im up) if you can solve this.
I have a table called file_versions - he it setup like so
Code:
version_id file_id session_id parent
1 1 1 0
5 2 1 0
20 13 1 5
21 20 1 5
25 6 1 1
I then duplicate this session 1 like so:
Code:
INSERT INTO file_versions
( session_id
, file_id
, parent )
SELECT
' 2
, file_id
, parent
FROM file_versions
WHERE session_id = 1
So I now have
Code:
version_id file_id session_id parent
1 1 1 0
5 2 1 0
20 13 1 5
21 20 1 5
25 6 1 1
26 1 2 0
27 2 2 0
28 13 2 5
29 20 2 5
30 6 2 1
So now the question. I need to change the parents of session 2 so they are relational to their version_id (except those who have a parent of 0)
so it should look like this if it worked:
Code:
version_id file_id session_id parent
1 1 1 0
5 2 1 0
20 13 1 5
21 20 1 5
25 6 1 1
26 1 2 0
27 2 2 0
28 13 2 27
29 20 2 27
30 6 2 26
I had this working a while back, but something happened.... Have no clue what. I may have modified it without noticing at some point. (this looks wrong to me now because there is no way to know what you are grabbing)
Code:
UPDATE file_versions
SET parent = parent + ( LAST_INSERT_ID( ) - ( SELECT version_id
FROM (
SELECT *
FROM file_versions
WHERE session_id = 1
ORDER BY version_id ASC
LIMIT 1
) AS x ) )
WHERE session_id = 2
AND parent !=0';
make it $35 if you can do this in one query. But im not 100% that is even possible.