Solved

Help with SQL query

Posted on 2012-03-25
2
246 Views
Last Modified: 2012-03-25
I'm having some problems with a query I'm trying to put together.

I have the following tables.

FOLDERS
id
name
trash
parent_id
create_user_id

PERMISSION
id
user_id
folder_id

What I want to do is list all folders where the user has an entry in the PERMISSIONS table for.

So there are two conditions

1) List folders where the parent_id = a supplied ID, and where the user has an entry in the PERMISSIONS table
2) List folders where the user isn't the creator of the folder, but is in the PERMISSIONS folder

This is what I've got so far...
SELECT f.id,f.name,f.trash,f.parent_id,f.create_user_id,f.create_date FROM folders AS f, folder_permissions AS p WHERE f.trash = 0 AND p.user_id = '".$user_id."' AND p.folder_id = f.id  AND (f.parent_id = '".$parent_id."' OR p.user_id != f.create_user_id) GROUP BY f.id ORDER BY f.name ASC

Can anyone point out where I might be going wrong?
0
Comment
Question by:SheppardDigital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
fundacionrts earned 500 total points
ID: 37762990
SELECT DISTINCT
      f.id,
      f.name,
      f.trash,
      f.parent_id,
      f.create_user_id,
      f.create_date
FROM
      folders AS f
            INNER JOIN folder_permissions AS p ON p.folder_id = f.id
WHERE
      f.trash = 0 AND
      p.user_id = '".$user_id."' AND
      (f.parent_id = '".$parent_id."' OR p.user_id != f.create_user_id)
ORDER BY
      f.name ASC
0
 

Author Closing Comment

by:SheppardDigital
ID: 37763107
Perfect, thank you
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question