Many thanks for reading ,
I have the following table (view)
#id_internal type BOOK_ID Writer Title Loan_person_id Loan_Date Return_Date
120 1 1002 Writer1 Book1 2 2012-05-21 2012-06-04
131 0 1002 Writer1 Book1 2 0000-00-00 2012-05-21
134 0 1002 Writer1 Book1 2 0000-00-00 2012-05-21
153 1 1002 Writer1 Book1 2 2012-05-21 2012-06-04
162 0 1002 Writer1 Book1 2 0000-00-00 2012-05-21
165 1 1002 Writer1 Book1 2 2012-05-21 2012-06-04
252 1 1012 Writer2 Book2 2 2012-05-23 2012-06-06
253 0 1012 Writer2 Book2 2 0000-00-00 2012-05-23
383 1 1012 Writer2 Book2 2 2012-05-23 2012-06-06
389 0 1012 Writer2 Book2 2 0000-00-00 2012-05-24
13 1 1008 Writer3 Book3 3 2012-05-20 2012-06-03
created which basically models my small applica!tion for a school library loan log.
I am trying to find out a way to create an sql statement that would do the following: Combine two rows at a time based in the id_internal field (shown in the picture) (first two rows - more two etc until no tuples exist or there is only one at the end) and create a new one with one more column.
What this is all about is that one row of the set (with type = 1) describes the book loan i.e. when the book was loaned and when it was supposed to be returned to the library. The second row (which always has as Loan_Date the time 0000:00:00 and the field type = 0 ) describes the true date the book was returned. The new row will have all the information contained in the first row and as the new column the true return date of the book. There are columns for Book_ID and Loan_person_id (for the reader who borrowed the book) and TYPE with values 0 (return ) and 1 (loan).
From my basic to early intermediate competence in SQL, I fail to use correctly the GROUP BY and GROUP CONCAT.
Looking forward for answers or directions.
Many thanks again ,
Dinos
Edit: The results should be in the form (let us use a view)
Before Processing: #id_internal type BOOK_ID Writer Title Loan_person_id Loan_Date Return_Date 120 1 1002 Writer1 Book1 2 2012-05-21 2012-06-04 131 0 1002 Writer1 Book1 2 0000-00-00 2012-05-21 After processing : Keep one of two id_internal (does not matter): #id_internal type BOOK_ID Writer Title Loan_person_id Loan_Date Return_Date Real_Return_Date 120 1 1002 Writer1 Book1 2 2012-05-21 2012-06-04 2012-05-21
Many Thanks