For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > March 2005 > Possible to see another query as a table?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Possible to see another query as a table?
Thone

2005-02-26, 8:56 pm

Hi
I wonder is there anyway to query from the result of another query.
Like:

SELECT ... FROM order, (SELECT *, SUM(price) FROM orderlist GROUP BY
order_id) WHERE order.id = orderlist.order_id

something like that.

Thanks You

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
David Hobbs

2005-02-27, 3:56 am

Well, you can do things like the following ....

SELECT dataset1.field1, dataset1.field2, dataset2.field3, dataset2.field4
FROM dataset1, dataset2 WHERE dataset1.field3 = dataset2.field5


NB: Substitute as many datasets and fields as you like....eg

Rgds

Dave.


"Thone" <theeraputhm@siamsite.com> wrote in message
news:4220d5e5_2@127.0.0.1...
> Hi
> I wonder is there anyway to query from the result of another query.
> Like:
>
> SELECT ... FROM order, (SELECT *, SUM(price) FROM orderlist GROUP BY
> order_id) WHERE order.id = orderlist.order_id
>
> something like that.
>
> Thanks You
>
> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
> News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
> Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption
> =----



Vigil

2005-02-27, 3:56 am

On Sun, 27 Feb 2005 02:56:17 +0700, Thone wrote:

> I wonder is there anyway to query from the result of another query.


Subqueries are supported as of MySQL 4.1.

http://dev.mysql.com/doc/mysql/en/subqueries.html

--

..

NSpam

2005-03-02, 4:00 pm

Vigil wrote:
> On Sun, 27 Feb 2005 02:56:17 +0700, Thone wrote:
>
>
>
>
> Subqueries are supported as of MySQL 4.1.
>
> http://dev.mysql.com/doc/mysql/en/subqueries.html
>

Yup, assuming I've interpreted your original post correctly then Vigil
is correct.

SELECT * from table_A
WHERE table_A.id IN
(
SELECT table_b.id
WHERE onecriteria = anothercriteria
)

I don't guarrentee the syntax but hopefully the concept survives
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com