我有一个显示书的桌子。但是,我希望每个唯一的电子邮件地址(strContactEmail
)仅显示1本书。我尝试了以下查询,但没有成功。任何帮助将不胜感激。
$sql = "SELECT lngbookid, strTitle, strAuthor, strcoursecode, strISBN, ".
" strcontactname, DISTINCT(strContactEmail) AS strContactEmail, ".
" curPrice, ysnsalerent, dtmpostdate, memcomments, school, ".
" ASIN, BookIMG, ISBN10, ISBN13, Updated, ".
" datetime, user_ip, NoOtherBooks ".
" FROM tblbooks ".
" WHERE strcoursecode LIKE '%$search%' ".
" ORDER BY datetime DESC LIMIT 50";
最佳答案
尝试使用GROUP BY语句:
http://www.w3schools.com/sql/sql_groupby.asp