single sql statement

  • Can someone please help me ?

    I need to write a single sql statement which retrieves the list of fruits, and the usernames of the users which have access to them. Use the tables below.

    `users` table

    username |group |password

    bchen |users |********

    jmax |admin |********

    mwilson |users |********

    `fruits` table

    fruit |access

    banana |users

    blueberry |admin

    cherry |users

    papaya |users

    strawberry |admin

    The output of the sql statement should look like this:

    fruit |username

    banana |bchen

    banana |mwilson

    blueberry |jmax

    cherry |bchen

    cherry |mwilson

    papaya |bchen

    papaya |mwilson

    strawberry |jmax

  • select fruit, username

    from fruits

    inner join

    users on

    fruits.access = users.group

    order by fruit







    **ASCII stupid question, get a stupid ANSI !!!**

  • Is this also ok ?

    select f.fruit,u.username from fruits f

    inner join users u

    on f.access = u.group

  • It's the exact same query except for the order by part.  In your sample results you seem to require the data to be returned by fruit name which is what the order by does.  The question of the validity of the results however returns to you or the person who requested this query because only you or them can answer this one.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply