sql - Return unique rows based on minimum id in mysql -
i've stuck on this:
need guid based on minimum id , remove other duplicates (guid, id). id unique field here.
+-----------------------------+------+-------------+ | guid | id | post_parent | +-----------------------------+------+-------------+ | 5.jpg | 7626 | 2418 | | 3.jpg | 7625 | 2418 | | 2.jpg | 5972 | 2418 | | 2.jpg | 3000 | 2420 | | 0.jpg | 3205 | 2420 | | 9.jpg | 9205 | 2419 | +-----------------------------+------+-------------+
so want:
+-----------------------------+------+-------------+ | guid | id | post_parent | +-----------------------------+------+-------------+ | 2.jpg | 5972 | 2418 | | 2.jpg | 3000 | 2420 | | 9.jpg | 9205 | 2419 | +-----------------------------+------+-------------+
sure, may use this:
select guid, id wp_posts id = ( select min(id) wp_posts post_parent="2418");
but need data table, not single rows.
select * wp_posts p, (select min(id) id, post_parent wp_posts group post_parent) mins p.id = mins.id , mins.post_parent = p.post_parent
Comments
Post a Comment