An SQL-query puzzle... SELECT max 2 rows from tables having id 'a' or id ' b' or id 'c'...

From: Date: Mon, 20 Nov 2000 11:58:12 +0000
Subject: An SQL-query puzzle... SELECT max 2 rows from tables having id 'a' or id ' b' or id 'c'...
Groups: php.db 
Request: Send a blank email to php-db+get-4574@lists.php.net to get a copy of this message
Hey hey hey... I`ve stumbled across a little SQL puzzle here... maybe some of you can help... I am building a "main page" for many "sub main pages" The idea is to have several pages displaying newsflashes for their specific subject... Example: Main page 1 only contains news about a place called Grewin Main page 2 only contains news about a place called Orklan Main page 3 only contains news about a place called Lillo Main page 4 only contains news about a place called Dogmax The news for these sites have already been stored in a MySQL table called article. The relation between the article and the specific site is stored in a table calles newsportal. NOW, I want to select the 2 top stories from each of these portals, to display them on a "main-main page"... So the main page displayes the two newest articles from page 1, 2, 3 and 4. A total of eight articles in this case... Maybe this is really easy, or maybe I have to reconstruct the db.... I`m using MySQL.... Any ideas will be GREATLY appreciated! -------------------------- Maybe something like this: SELECT article.story as story, article.date as date FROM article, newsportal WHERE article.articleid = newsportal.articleid AND newsportal.portalid = 1 OR newsportal.portalid = 2 OR newsportal.portalid = 3 OR newsportal.portalid = 4 ORDER BY date DESC LIMIT 0, 8 ---- no , that wasnt right... But maybe itll help you understand... :) From SQL puzzler!

« previous php.db (#4574) next »