MySQL Forums
Forum List  »  Newbie

Re: Query between 2 related tables - duplicated records in the result set for every record in the 2nd table that it matches.
Posted by: laptop alias
Date: November 02, 2009 07:12AM

There is, but this kind is most easily handled at the application level, e.g. with a bit of PHP.

Anyway, here's one way:
SELECT * FROM eav;
+----+--------+--------+------+
| id | userid | title  | data |
+----+--------+--------+------+
|  1 |    231 | name   | John |
|  2 |    231 | age    | 24   |
|  3 |    231 | gender | man  |
|  4 |    232 | name   | Pete |
|  5 |    232 | age    | 34   |
|  6 |    232 | gender | man  |
+----+--------+--------+------+

SET @userid ='';

SELECT id,IF(userid=@userid,'-',userid)userid,title,data,@userid:=userid FROM eav;
+----+--------+--------+------+-----------------+
| id | userid | title  | data | @userid:=userid |
+----+--------+--------+------+-----------------+
|  1 | 231    | name   | John |             231 |
|  2 | -      | age    | 24   |             231 |
|  3 | -      | gender | man  |             231 |
|  4 | 232    | name   | Pete |             232 |
|  5 | -      | age    | 34   |             232 |
|  6 | -      | gender | man  |             232 |
+----+--------+--------+------+-----------------+

Options: ReplyQuote


Subject
Written By
Posted
Re: Query between 2 related tables - duplicated records in the result set for every record in the 2nd table that it matches.
November 02, 2009 07:12AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.