Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2010 01:58
Show Gist options
  • Save anonymous/286461 to your computer and use it in GitHub Desktop.
Save anonymous/286461 to your computer and use it in GitHub Desktop.
SELECT fabric.CodFabric,fabric.Fabricante,fabric.Pais,
COUNT(distinct fabrics.CodJogo) as TotFab,COUNT(distinct publishs.CodJogo) as TotPub
FROM fabric
LEFT JOIN fabrics on fabric.CodFabric = fabrics.CodFabric
LEFT JOIN publishs on fabric.CodFabric = publishs.CodFabric
GROUP BY fabric.CodFabric
EXPLAIN
1 SIMPLE fabric ALL NULL NULL NULL NULL 1078 Using temporary; Using filesort
1 SIMPLE fabrics index NULL PRIMARY 8 NULL 10801 Using index
1 SIMPLE publishs index NULL PRIMARY 8 NULL 2086 Using index
CREATE TABLE `fabric` (\n `CodFabric` int(11) NOT NULL default '0',\n `Fabricante` varchar(40) NOT NULL default '',\n `Pais` int(11) default NULL,\n `Imagem` longblob,\n `Descricao` mediumtext,\n PRIMARY KEY (`CodFabric`),\n KEY `Fabricante` (`Fabricante`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `fabrics` (\n `CodJogo` int(11) NOT NULL default '0',\n `CodFabric` int(11) NOT NULL default '0',\n PRIMARY KEY (`CodJogo`,`CodFabric`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `publishs` (\n `CodJogo` int(11) NOT NULL default '0',\n `CodFabric` int(11) NOT NULL default '0',\n PRIMARY KEY (`CodJogo`,`CodFabric`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment