I'd like to perform a SELECT
query on an existing recordset, for example:
query1 = 'Select * from products where onSale = 1'
and then
query2 = 'Select * from recordset开发者_C百科1 where ....'
where recordset1
is the number of rows that query1
returned.
Any suggestions? Thanks!
Use a subquery:
SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);
If this is just in MySQL then you can do
SELECT * FROM (SELECT * FROM products WHERE onsale =1) AS OnSaleProducts
To use your example,
SELECT distinct colorid from (SELECT * FROM product, collectionItems where collectionItems.CollectionID = '6' and collectionItems.ProductID = product.barcode) As 1stResults where typeid = '".$_SESSION['typeid']."' and stoneid = '".$_SESSION['stoneid']."' order by colorid asc;
If you don't want to run the first query again, consider using a temporary table to store the results, and then querying from that, as if it was a normal table.
Also, you could populate temporary table.
For example:
CREATE TEMPORARY TABLE temp_table SELECT * FROM products WHERE onsale = 1
You wrote: where recordset1 is the number of rows that query1 returned. Any suggestions? Thanks!
The number of rows can be stored in a variable, in this case you don't need resault set.
精彩评论