0

I have an Users database, a Posts database and a PostPermissions database.

The database scheme (that you need to know so you can understand) is something like this:

Post:

id :int(11) | description :varchar(255) | creator_user_id :int(11)

PostPermissions:

id :int(11) | post_id :int(11) | entity_id :int(11) | permission :tinyint(1) (bool) | orderby tinyint(4)

So, in the PostPermissions we can have different type of permissions, but that is already working.

I've made something like this on my MySQL Query:

SELECT Post.id
FROM posts as Post
    LEFT JOIN post_permissions AS PostPermission
    ON Post.id = PostPermission.post_id
WHERE Post.creator_user_id = 4
GROUP BY Post.id HAVING GROUP_CONCAT(PostPermission.permission) like "%1"

But there are two problems, GROUP_CONCAT(PostPermission.permission) will retrieve, for all posts, all the permission values, and if i put GROUP_CONCAT(DISTINCT PostPermission.permission) it will retrieve only a zero and an one ordered by the first to be catched...

There is any way to process only the last row of PostPermissions (because they are already ordered) that had been matched with the posts?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
cusspvz
  • 5,143
  • 7
  • 30
  • 45
  • SQL tables are [unordered](http://stackoverflow.com/a/10418282/). What do you mean by "*last row*"? That with the maximal `id`? – eggyal Dec 28 '12 at 21:03
  • My problem is that on my original Query, i have more inner joins and it repeats the founded `PostPermission `rows with GROUP_CONCAT... – cusspvz Dec 29 '12 at 01:08
  • By the way, it can be with ID because i store the permissions on the database with the correct all>groups>users order. – cusspvz Dec 29 '12 at 01:09

0 Answers0