Help with a select statement!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ferreira

    #1

    Help with a select statement!

    Hi.

    I have a simple query that is similar to this one:

    SELECT distinct b.username from permissions a, users b, links c where
    a.user_id = b.id and c.information = 14;

    In this case, it selects the all users details from table 'user' that are
    permissioned to access a certain information with id = 14.

    The problem is that I need to select the users that are not permissioned but
    I have sql v3.23 and I canot use union.

    In other words, I need to do a select b.username from users b where
    b.username not in "the result" of the last select.

    Can you give me a help?

    Thanks,
    Ana


  • Bill Karwin

    #2
    Re: Help with a select statement!

    Ferreira wrote:[color=blue]
    > SELECT distinct b.username from permissions a, users b, links c where
    > a.user_id = b.id and c.information = 14;
    >
    > In this case, it selects the all users details from table 'user' that are
    > permissioned to access a certain information with id = 14.
    >
    > The problem is that I need to select the users that are not permissioned but
    > I have sql v3.23 and I canot use union.[/color]

    Does this give the results you need?

    select distinct b.username
    from permissions a on a.user_id = b.id inner join links c
    on (a.something = c.something and c.information = 14)
    right outer join users b on a.user_id = b.id
    where a.user_id is null;

    You omitted the join criteria for how links is related to the other
    tables, so substitute the "something" identifiers for your actual join
    columns.

    Regards,
    Bill K.

    Comment

    Working...