sql: subselect howto?
| From: | Dieter Kneffel | Date: | Wed, 09 Aug 2000 21:55:56 +0000 |
| Subject: | sql: subselect howto? | ||
| Groups: | php.db php.general | ||
| Request: | Send a blank email to php-general+get-11003@lists.php.net to get a copy of this message | ||
Can someone please give an example of a subselect! It should be
sufficient to show really basic usage, I'll figure out the rest. Just
can't test it now as I haven't access at the moment to the (Oracle8)
database the code is intended for.
My first suggestion goes here, please apply necessary fixes!
--
Imagine we have two really basic tables: 'items' and 'users'.
items has 2 cols: 'item' (int) and 'userid' (int)
users has 2 cols: 'name' (char) and 'userid' (int)
Now lets say, I need to show all 'name's and 'item's that belong to
users with an 'm' as the first letter in their name ('name' from table
users)
select item,userid
from items
where userid in (select userid from users where name
like 'm%');
Probably this returns only 'item' and 'userid' ??? So, how do I also get
the
corresponding 'name' values returned?
As stated above, this is meant for educational purposes. I know how to
do it (e.g. in MySQL) using two separate queries, so please reply only
if
you can help with the subselect.
Thank you very much,
Dieter