pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
find the number of rows for each table 2+ messages / 2 participants [nested] [flat]
* find the number of rows for each table @ 2000-06-15 20:10 Patrick Coulombe <pcoulombe@mediacces.com> 2000-06-18 14:16 ` Re: find the number of rows for each table Peter Eisentraut <peter_e@gmx.net> 0 siblings, 1 reply; 2+ messages in thread From: Patrick Coulombe @ 2000-06-15 20:10 UTC (permalink / raw) To: pgsql-sql Hi, I want to find the number of rows for each table (2) in 1 query, the query is: select distinct * from medias, contacts WHERE medias.media_id = contacts.media_id AND medias_categories.media_id = medias.media_id AND medias_categories.categorie_id = 1 -------- 700 rows If I want to find the number of row for medias (for the same query) I have to do a other query : select distinct * from medias WHERE medias.media_id = contacts.media_id AND medias_categories.media_id = medias.media_id AND medias_categories.categorie_id = 1 -------- 60 rows I search for a solution, I try that : select distinct *, count(distinct (medias.media_id)), count(distinct (contacts.contact_id)) from medias, contacts WHERE medias.media_id = contacts.media_id AND medias_categories.media_id = medias.media_id AND medias_categories.categorie_id = 1 ------------------------------------------------- ERROR: parser: parse error at or near "distinct" don't work, as you can see. I need help, please. Patrick ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: find the number of rows for each table 2000-06-15 20:10 find the number of rows for each table Patrick Coulombe <pcoulombe@mediacces.com> @ 2000-06-18 14:16 ` Peter Eisentraut <peter_e@gmx.net> 0 siblings, 0 replies; 2+ messages in thread From: Peter Eisentraut @ 2000-06-18 14:16 UTC (permalink / raw) To: Patrick Coulombe <pcoulombe@mediacces.com>; +Cc: pgsql-sql Patrick Coulombe writes: > I want to find the number of rows for each table (2) in 1 query, > the query is: To find the number of rows in one table you do SELECT COUNT(*) FROM table; To find the number of rows in two tables you send two queries like that. There's no good way to do it in one shot, nor is there any reason why there should: if you want two different pieces of information you send two queries. Also note that some of your attempts are going to be wildly slower than just two straightforward count(*) queries. > > select distinct * from medias, contacts WHERE medias.media_id = > contacts.media_id AND medias_categories.media_id = medias.media_id AND > medias_categories.categorie_id = 1 > -------- > 700 rows > > > If I want to find the number of row for medias (for the same query) I > have to do a other query : > > select distinct * from medias WHERE medias.media_id = > contacts.media_id AND medias_categories.media_id = medias.media_id AND > medias_categories.categorie_id = 1 > -------- > 60 rows > > > I search for a solution, I try that : > > select distinct *, count(distinct (medias.media_id)), count(distinct > (contacts.contact_id)) from medias, contacts WHERE medias.media_id = > contacts.media_id AND medias_categories.media_id = medias.media_id AND > medias_categories.categorie_id = 1 > ------------------------------------------------- > ERROR: parser: parse error at or near "distinct" > > don't work, as you can see. -- Peter Eisentraut Sernanders väg 10:115 peter_e@gmx.net 75262 Uppsala http://yi.org/peter-e/ Sweden ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-06-18 14:16 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2000-06-15 20:10 find the number of rows for each table Patrick Coulombe <pcoulombe@mediacces.com> 2000-06-18 14:16 ` Peter Eisentraut <peter_e@gmx.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox