December 17, 2006 at 7:22 am
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
December 17, 2006 at 7:58 am
select fruit, username
from fruits
inner join
users on
fruits.access = users.group
order by fruit
**ASCII stupid question, get a stupid ANSI !!!**
December 18, 2006 at 8:12 am
Is this also ok ?
select f.fruit,u.username from fruits f
inner join users u
on f.access = u.group
December 18, 2006 at 8:16 am
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