
December 20th, 2012, 08:35 PM
|
|
competitions at lottos.com.au
|
|
Join Date: Jun 2003
Posts: 251
Time spent in forums: 1 Day 19 h 6 m 7 sec
Reputation Power: 10
|
|
|
Select all rows and select just first row?
Currently do a select to produce rows of posts for a specific topic:
$queryposts = $db->query("SELECT p.pid, p.author, p.message, p.subject, p.dateline, m.username FROM posts p INNER JOIN members m ON m.username = p.author WHERE.... ORDER BY p.pid ASC");
I would like to ALSO select the FIRST post row for the same topic, assign it to a variable. I could do this via:
$firstpostquery = $db->query("SELECT pid FROM posts WHERE... ORDER BY dateline LIMIT 1");
$isthefirstpost = $db->fetch_array($firstpostquery);
$db->free_result($firstpostquery);
However the second select seems inefficient because I'm already grabbing all rows in the first select and the second select has to go through the entire posts table again.
Is there a way to use the first select and also do a sub select for also obtaining the first row - or some other method that is more efficient?
|