Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 appending tables in mysql

Author  Topic 

rsi256
Starting Member

1 Post

Posted - 2014-07-11 : 13:47:58
Hi
I have a question on appending and deleting entries in mysql table.

This is my sample table.
table name: details

id_name | model | mode | media| first | end | id | level |
+--------------------+-------+---------+-----+-------+-------+--------+--------+
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14684 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14838 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15236 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 3 | 14033 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 3 | 14756 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 3 | 14892 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 3 | 15304 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 3 | 15550 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | T0 | 15550 | 16050 | 6255 | q |
| PSK_30s1189731L001 | -1 | 1 | 3 | 999 | 7531 | 9808 | c |
| PSK_30s1189731L001 | -1 | 1 | 3 | 999 | 6487 | 9808 | c |
| PSK_30s1189731L001 | -1 | 1 | 5 | 6609 | 8257 | 9808 | c |
| PSK_30s1189731L001 | -1 | 1 | 3 | 999 | 6285 | 9808 | c |
| PSK_30s716971L003 | -1 | 1 | T0 | 23604 | 24104 | 2285 | c |
| PSK_30s716971L003 | -1 | 1 | 3 | 24070 | 24104 | 2285 | c |
| PSK_30s716971L003 | -1 | 1 | 3 | 24070 | 27133 | 2285 | c |
| PSK_30s716971L003 | -1 | 1 | 3 | 24070 | 28318 | 2285 | c |
| PSK_30s716971L003 | 1 | 1 | N | 24070 | 28326 | 2285 | c |
| PSK_30s716971L003 | -1 | 1 | 5 | 27036 | 28326 | 2285 | c
| PSK_30s716971L003 | -1 | 1 | 5 | 27483 | 28326 | 2285 | c

I have numerous entries of same id name belonging to same median number.However,I want to only retain the entries having the longest first and end position and discard the remaining entries


For eg for id name ="PSK_30s1207681L002" AND median = 5 we have four entries

id_name | model | mode | media| first | end | id | level |
+--------------------+-------+---------+-----+-------+-------+--------+--------+
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14684 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14838 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15236 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |


but I want to retain only the one having longest first and end points ie

| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |


Here ,since for id name ="PSK_30s1207681L002" & median = N we have only 1 entry I want retain that one.



My final output in mysql table should look like this.

id_name | model | mode | media| first | last | id | level |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 3 | 14033 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | T0 | 15550 | 16050 | 6255 | q |
| PSK_30s1189731L001 | -1 | 1 | 3 | 999 | 7531 | 9808 | c |
| PSK_30s1189731L001 | -1 | 1 | 5 | 6609 | 8257 | 9808 | c |
| PSK_30s716971L003 | -1 | 1 | T0 | 23604 | 24104 | 2285 | c |
| PSK_30s716971L003 | -1 | 1 | 3 | 24070 | 28318 | 2285 | c |
| PSK_30s716971L003 | 1 | 1 | N | 24070 | 28326 | 2285 | c |
| PSK_30s716971L003 | -1 | 1 | 5 | 27036 | 28326 | 2285 | c


Is there anything that I could do to append it?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-07-11 : 14:11:40
This forum is for Microsoft SQL Server, so you are likely to get better/faster/more accurate answers at a MySQL forum than here.
Go to Top of Page
   

- Advertisement -