tags:

views:

31

answers:

2

hi,

i am using php with mySql server, pretty new to all the sql and i have a question: i have a query:

$book_copy_user =  "SELECT * FROM copy_book " .
                   "JOIN copy_user_own " .
                   "ON copy_book.copy_id = copy_user_own.copy_id " .
                   "WHERE copy_user_own.user_id=1";

$res1 =mysql_query($sql1) or die (mysql_error());

which returns something like

[{"copy_id":"1","book_id":"1","user_id":"1"},
{"copy_id":"2","book_id":"2","user_id":"1"},
{"copy_id":"3","book_id":"3","user_id":"1"},
{"copy_id":"4","book_id":"4","user_id":"1"}]

i would like to do 3 different select on the result with a where clause, but when trying to so it tells me that there is more the one column.

my question is: is there a way that i can use the select result and apply select on it? if so how can i relate to the fields of the in the select result?

please provide code samples

thanks you all you are saints :)

A: 
SELECT * FROM (SELECT * FROM copy_book JOIN copy_user_own ON copy_book.copy_id = copy_user_own.copy_id WHERE copy_user_own.user_id=1) WHERE copy_id = 4

althrough I'm not sure if it works in mysql.

No, after running select you cannot apply another on it.

Yossarian
+1  A: 

You can select the data into a temporary table and perform more queries on that table.

CREATE TEMPORARY TABLE temp_table SELECT ...

But I think it would be best if you posted your actual problem, it is very likely that there are much better solutions.

soulmerge