0
I want the results of my poll to be sorted by the amount of votes you have in the other exclusive table to compute votes.
Currently my results come out like this:
I have two tables, this one below belongs to the answers to be voted. The column enquete_id indicates the number of the poll that is linked to the voting responses.
CREATE TABLE `respostas` (
`id` int(11) NOT NULL,
`enquete_id` int(11) NOT NULL,
`opcao` varchar(500) NOT NULL DEFAULT ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
And this table belongs to the votes, this is where they will be computed:
CREATE TABLE `votos` (
`id` int(11) NOT NULL,
`enquete_id` int(11) NOT NULL,
`opcao_id` int(11) NOT NULL,
`data` int(11) NOT NULL,
`ip` varchar(100) NOT NULL DEFAULT ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I tried something like that, but it didn’t work out, even the times it did, Unfortunately there were no zeroed votes, no options to vote that were without votes.
SELECT *
FROM resposta op
INNER JOIN votos vt ON (vt.enquete_id = op.enquete_id)
WHERE op.enquete_id='1'
GROUP BY op.id ORDER BY vt.opcao_id
This answers your question? Doubt LEFT JOIN SQL
– tvdias
I think that’s about it, but I still can’t do it.
– Léo