Page 1 of 1

Perform a query without a view I've created msyql

Posted: Sat Oct 13, 2012 9:04 am
by lovelf
The following is the queries:

Code: Select all

<?php
mysql_query("CREATE VIEW F1LIMIT5 as SELECT DISTINCT albumid from tags WHERE id3='$value' AND flag!='w' AND visibility='t' ORDER BY datetimep DESC limit 5");

$aresult=mysql_query("SELECT * from tags where albumid in (SELECT * FROM F1LIMIT5) and id3='$value' AND flag!='w' AND visibility='t' order by datetimep desc"); 
?>
I would need not to use the create view query, and instead make it a single query, substitute the select * from f1limit5

Re: Perform a query without a view I've created msyql

Posted: Sat Oct 13, 2012 5:02 pm
by McInfo
I'm not sure what you are asking for.

Re: Perform a query without a view I've created msyql

Posted: Sun Oct 14, 2012 10:49 am
by Mordred
What you do:

CREATE VIEW myview AS SELECT <subselect>
SELECT x IN (SELECT * FROM myview) ...

What you can do:
SELECT x in (<subselect>) ...

Re: Perform a query without a view I've created msyql

Posted: Wed Oct 17, 2012 10:23 am
by lovelf
Doing this:

Code: Select all

<?php
$aresult=mysql_query("SELECT * from tags where albumid in (DISTINCT albumid from tags WHERE id3='$valued' AND flag!='w' AND visibility='t' ORDER BY datetimep DESC limit 5) and id3='$value' AND flag!='w' AND visibility='t' order by datetimep desc");
?> 
Returns php errors, I really want to get rid of the view.

Re: Perform a query without a view I've created msyql

Posted: Fri Oct 19, 2012 9:13 am
by McInfo
Maybe this?

Code: Select all

$aresult = mysql_query(sprintf("SELECT * FROM tags WHERE id3='%s' AND flag!='w' AND visibility='t' ORDER BY datetimep DESC", mysql_real_escape_string($value)));