Re: joining two tables having the same PK with another table
Posted by: Anders Ingemann
Date: March 16, 2006 04:59AM

Hi,

apparently nobody knows the answer... or didn't understand the question.
Anyhow, I think I have the solution.
I post it for two reasons:
- I'm asking you if it works
- So others with the same problem know what to do

The Select should look like this:
SELECT
all.name
all.rights_id
all.value
all.users_id
FROM (
SELECT
rights.name
getDefinedRow(level_rights.rights_id,additional_rights.rights_id) AS rights_id
getDefinedRow(level_rights.value,additional_rights.value) AS value
getDefinedRow(level_rights.users_id,additional_rights.users_id) AS users_id
FROM rights
LEFT JOIN level_rights ON rights.id=level_rights.rights_id
LEFT JOIN additional_rights ON rights.id=additional_rights.rights_id
WHERE additional_rights.rights_id IS NOT NULL OR level_rights.rights_id IS NOT NULL
) all
INNER JOIN users ON users.id=all.users_id
[WHERE all.users_id=1]

getDefinedRow is a stored function, you can see it here: http://forums.mysql.com/read.php?125,75798,76075#msg-76075

However, I still believe this can be done without a subselect.



Edited 2 time(s). Last edit at 03/16/2006 05:02AM by Anders Ingemann.

Options: ReplyQuote


Subject
Written By
Posted
Re: joining two tables having the same PK with another table
March 16, 2006 04:59AM


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.