mysql - Multiple inner join on a table where rows represent data attributes -
i have following user table (don't ask me why :) )
| id | cid | attr | text | rdate | --------------------------------------- | 1 | 1 | name | joe | null | | 2 | 1 | date | null | 10.05.2014 | | 3 | 1 | stat | 2 | null | ---------------------------------------- | 4 | 2 | name | joe | null | | 5 | 2 | date | null | 05.05.2014 | | 6 | 2 | stat | 1 | null | ---------------------------------------- | 7 | 3 | name | joe | null | | 8 | 3 | date | null | 03.05.2014 | | 9 | 3 | stat | 2 | null |
as can see every user's attribute (name, date, stat) row in table. attributes same cid belong same user.
i delete entries refer user attribute date before 08.05.2014 , attribute stat not 2. after running query table be:
| id | cid | attr | text | rdate | --------------------------------------- | 1 | 1 | name | joe | null | | 2 | 1 | date | null | 10.05.2014 | | 3 | 1 | stat | 2 | null | ---------------------------------------- | 7 | 3 | name | joe | null | | 8 | 3 | date | joe | 03.05.2014 | | 9 | 3 | stat | 2 | null |
is possible? inner join on same table?
group cid
, use having
clause run group functions check out requirements in every single group
delete your_table cid in ( select * ( select cid your_table group cid having sum(attr = 'date' , `date` < '2014-05-08') > 0 , sum(attr = 'stat' , `text` = 2) = 0 ) tmp_tbl )
in mysql can't delete same table selecting from. can trick mysql subquery in example above.
Comments
Post a Comment