MyBB Community Forums

Full Version: Mysql dublicate rows & using one query with two while loops
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to use a query in mybb_posts & attachment

for now i am using
<?

<?
//2nd while loop
$queryy=mysql_query("SELECT   
 mybb_posts.pid, mybb_posts.subject,mybb_posts.message,mybb_posts.tid,
mybb_attachments.pid,mybb_attachments.aid
FROM mybb_posts
INNER JOIN mybb_attachments
USING(pid,pid)
ORDER  BY  `aid` DESC
LIMIT 7")or die($query."<br/><br/>".mysql_error());

while ($lista=mysql_fetch_array($queryy))
{
echo '


			<img src="attachment.php?aid='.$lista["aid"].'   " alt="" />
				<h4><a href="#" >'.$lista["subject"].'</a></h4>

			';

}

?>

But this code is selecting all rows (duplicate & non-duplicate) I want to select only non-duplicate rows, how to do that ?
Try this query instead:

SELECT DISTINCT
mybb_posts.pid, mybb_posts.subject,mybb_posts.message,mybb_posts.tid,
mybb_attachments.pid,mybb_attachments.aid
FROM mybb_posts
INNER JOIN mybb_attachments
USING(pid,pid)
ORDER  BY  `aid` DESC
LIMIT 7
Not working, have you tried ?