Ciao a tutti.
Ho creato un database per un news system, ecco il dump della struttura
Le tabelle sono queste 4:codice:CREATE TABLE category ( id tinyint(4) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, PRIMARY KEY (id), UNIQUE KEY `name` (`name`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE `comment` ( id mediumint(9) NOT NULL AUTO_INCREMENT, author varchar(30) NOT NULL, authorEmail varchar(100) NOT NULL, authorURL varchar(200) NOT NULL, authorIP varchar(100) NOT NULL, `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', isApproved tinyint(1) NOT NULL DEFAULT '0', post_id smallint(6) NOT NULL, content text NOT NULL, karma mediumint(9) NOT NULL DEFAULT '0', PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE post ( id smallint(6) NOT NULL AUTO_INCREMENT, title varchar(50) NOT NULL, category_id tinyint(4) NOT NULL, author_id tinyint(4) NOT NULL DEFAULT '0', content longtext NOT NULL, isPublished tinyint(1) NOT NULL DEFAULT '0', creationDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00', lastEditDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00', likes smallint(6) NOT NULL, hates smallint(6) NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE `user` ( id tinyint(4) NOT NULL AUTO_INCREMENT, `name` varchar(16) NOT NULL, pass varchar(100) NOT NULL, IPaddress varchar(12) NOT NULL DEFAULT '0', permission_id tinyint(1) NOT NULL, PRIMARY KEY (id), UNIQUE KEY `name` (`name`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
[list=1][*]post - gli articoli[*]user - gli utenti che scrivono gli articoli[*]comment - i commenti agli articoli[*]category - le categorie degli articoli[/list=1]
Il problema è che non riesco a fare una semplice query che dovrebbe restituire questi campi:
codice:post.title, user.name, post.creationDate, category.name, post.content, COUNT(comment.id), post.likes, post.hates
Questo è il mio tentativo. Ho tralasciato category.name per dimenticanza, ma non fa niente per ora... intanto vorrei capire dove sbaglio con questa query
Praticamente mi restituisce solo un risultato, il primo articolo.codice:SELECT a.title, u.name AS author, a.creationDate, a.content, COUNT( c.id ) AS comments, a.likes, a.hates FROM ( backend.post AS a INNER JOIN backend.user AS u ON a.author_id = u.id ) INNER JOIN backend.comment AS c ON c.post_id = a.id ORDER BY creationDate DESC
Come posso risolvere?
Ringrazio in anticipo

Rispondi quotando
