PostgreSQL row not shown when count is zero2019 Community Moderator ElectionPostgreSQL “DESCRIBE TABLE”Inserting multiple rows in a single SQL query?Show tables in PostgreSQLCreating a copy of a database in PostgreSQLInsert, on duplicate update in PostgreSQL?Save PL/pgSQL output from PostgreSQL to a CSV fileHow can I drop all the tables in a PostgreSQL database?Select first row in each GROUP BY group?How to exit from PostgreSQL command line utility: psqlWhich version of PostgreSQL am I running?

What Happens when Passenger Refuses to Fly Boeing 737 Max?

What wound would be of little consequence to a biped but terrible for a quadruped?

Virginia employer terminated employee and wants signing bonus returned

How are showroom/display vehicles prepared?

Single word request: Harming the benefactor

How is the wildcard * interpreted as a command?

Accountant/ lawyer will not return my call

How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?

PTIJ: wiping amalek’s memory?

Am I not good enough for you?

Why was Goose renamed from Chewie for the Captain Marvel film?

Is it possible to avoid unpacking when merging Association?

Makefile strange variable substitution

Find longest word in a string: are any of these algorithms good?

Do recommendation systems necessarily use machine learning algorithms?

Do items de-spawn in Diablo?

Why the color red for the Republican Party

Intuition behind counterexample of Euler's sum of powers conjecture

What are actual Tesla M60 models used by AWS?

'The literal of type int is out of range' con número enteros pequeños (2 dígitos)

When a wind turbine does not produce enough electricity how does the power company compensate for the loss?

Can one live in the U.S. and not use a credit card?

Is "conspicuously missing" or "conspicuously" the subject of this sentence?

Does "Until when" sound natural for native speakers?



PostgreSQL row not shown when count is zero



2019 Community Moderator ElectionPostgreSQL “DESCRIBE TABLE”Inserting multiple rows in a single SQL query?Show tables in PostgreSQLCreating a copy of a database in PostgreSQLInsert, on duplicate update in PostgreSQL?Save PL/pgSQL output from PostgreSQL to a CSV fileHow can I drop all the tables in a PostgreSQL database?Select first row in each GROUP BY group?How to exit from PostgreSQL command line utility: psqlWhich version of PostgreSQL am I running?










0















I am trying to output total number of orders placed by customers of each country in the year 2018. Here's my query:



select country, count(country) 
from customers, orders
where customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by(country);


This prints out the correct values but countries with 0 orders are not outputted. I tried different types of joins as well (right join, left etc.) but still no luck. Anyone know how to fix this or know what might be wrong with it?










share|improve this question






















  • Tip of today: Always use modern, explicit JOIN syntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.

    – jarlh
    Mar 7 at 7:35















0















I am trying to output total number of orders placed by customers of each country in the year 2018. Here's my query:



select country, count(country) 
from customers, orders
where customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by(country);


This prints out the correct values but countries with 0 orders are not outputted. I tried different types of joins as well (right join, left etc.) but still no luck. Anyone know how to fix this or know what might be wrong with it?










share|improve this question






















  • Tip of today: Always use modern, explicit JOIN syntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.

    – jarlh
    Mar 7 at 7:35













0












0








0








I am trying to output total number of orders placed by customers of each country in the year 2018. Here's my query:



select country, count(country) 
from customers, orders
where customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by(country);


This prints out the correct values but countries with 0 orders are not outputted. I tried different types of joins as well (right join, left etc.) but still no luck. Anyone know how to fix this or know what might be wrong with it?










share|improve this question














I am trying to output total number of orders placed by customers of each country in the year 2018. Here's my query:



select country, count(country) 
from customers, orders
where customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by(country);


This prints out the correct values but countries with 0 orders are not outputted. I tried different types of joins as well (right join, left etc.) but still no luck. Anyone know how to fix this or know what might be wrong with it?







sql postgresql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 6:48









tirth96tirth96

114




114












  • Tip of today: Always use modern, explicit JOIN syntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.

    – jarlh
    Mar 7 at 7:35

















  • Tip of today: Always use modern, explicit JOIN syntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.

    – jarlh
    Mar 7 at 7:35
















Tip of today: Always use modern, explicit JOIN syntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.

– jarlh
Mar 7 at 7:35





Tip of today: Always use modern, explicit JOIN syntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.

– jarlh
Mar 7 at 7:35












2 Answers
2






active

oldest

votes


















1














use modern join not coma separated join, do count for orders.id



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and orders.date <='2018-12-31'
group by country


You don't need parenthesis after group by






share|improve this answer

























  • I tried left and right join, still doesn’t work

    – tirth96
    Mar 7 at 6:57











  • @tirth96 create table here in fiddle dbfiddle.uk/… it should work if not then you need to help us by creating fiddle then we can solve your problem

    – Zaynul Abadin Tuhin
    Mar 7 at 6:58












  • ok nvm this worked, do you know it can be done with just join, not left join

    – tirth96
    Mar 7 at 7:08











  • @tirth96 it will not work just by using join because with out left join you will loose the country from where still not ordered place

    – Zaynul Abadin Tuhin
    Mar 7 at 7:12






  • 1





    That LEFT JOIN returns regular INNER JOIN result. Move the orders.date conditions from WHERE to ON to get true LEFT JOIN result.

    – jarlh
    Mar 7 at 8:16


















2














use left join and move your where condition in ON clause



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by country





share|improve this answer























  • Tried that, still no luck

    – tirth96
    Mar 7 at 6:58






  • 1





    @tirth96: that should do exactly what you want. You need to edit and provide some sample data and the expected output on that data. Or create a short online example, e.g. here or here

    – a_horse_with_no_name
    Mar 7 at 7:07












  • ooh i see, this worked!

    – tirth96
    Mar 7 at 7:09











  • Do you know how I can do the same thing with just join?

    – tirth96
    Mar 7 at 7:09











  • @tirth96, you've to use left join - with inner join it's not possible

    – fa06
    Mar 7 at 7:10










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037647%2fpostgresql-row-not-shown-when-count-is-zero%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














use modern join not coma separated join, do count for orders.id



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and orders.date <='2018-12-31'
group by country


You don't need parenthesis after group by






share|improve this answer

























  • I tried left and right join, still doesn’t work

    – tirth96
    Mar 7 at 6:57











  • @tirth96 create table here in fiddle dbfiddle.uk/… it should work if not then you need to help us by creating fiddle then we can solve your problem

    – Zaynul Abadin Tuhin
    Mar 7 at 6:58












  • ok nvm this worked, do you know it can be done with just join, not left join

    – tirth96
    Mar 7 at 7:08











  • @tirth96 it will not work just by using join because with out left join you will loose the country from where still not ordered place

    – Zaynul Abadin Tuhin
    Mar 7 at 7:12






  • 1





    That LEFT JOIN returns regular INNER JOIN result. Move the orders.date conditions from WHERE to ON to get true LEFT JOIN result.

    – jarlh
    Mar 7 at 8:16















1














use modern join not coma separated join, do count for orders.id



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and orders.date <='2018-12-31'
group by country


You don't need parenthesis after group by






share|improve this answer

























  • I tried left and right join, still doesn’t work

    – tirth96
    Mar 7 at 6:57











  • @tirth96 create table here in fiddle dbfiddle.uk/… it should work if not then you need to help us by creating fiddle then we can solve your problem

    – Zaynul Abadin Tuhin
    Mar 7 at 6:58












  • ok nvm this worked, do you know it can be done with just join, not left join

    – tirth96
    Mar 7 at 7:08











  • @tirth96 it will not work just by using join because with out left join you will loose the country from where still not ordered place

    – Zaynul Abadin Tuhin
    Mar 7 at 7:12






  • 1





    That LEFT JOIN returns regular INNER JOIN result. Move the orders.date conditions from WHERE to ON to get true LEFT JOIN result.

    – jarlh
    Mar 7 at 8:16













1












1








1







use modern join not coma separated join, do count for orders.id



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and orders.date <='2018-12-31'
group by country


You don't need parenthesis after group by






share|improve this answer















use modern join not coma separated join, do count for orders.id



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and orders.date <='2018-12-31'
group by country


You don't need parenthesis after group by







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 7 at 8:35

























answered Mar 7 at 6:49









Zaynul Abadin TuhinZaynul Abadin Tuhin

16.1k21033




16.1k21033












  • I tried left and right join, still doesn’t work

    – tirth96
    Mar 7 at 6:57











  • @tirth96 create table here in fiddle dbfiddle.uk/… it should work if not then you need to help us by creating fiddle then we can solve your problem

    – Zaynul Abadin Tuhin
    Mar 7 at 6:58












  • ok nvm this worked, do you know it can be done with just join, not left join

    – tirth96
    Mar 7 at 7:08











  • @tirth96 it will not work just by using join because with out left join you will loose the country from where still not ordered place

    – Zaynul Abadin Tuhin
    Mar 7 at 7:12






  • 1





    That LEFT JOIN returns regular INNER JOIN result. Move the orders.date conditions from WHERE to ON to get true LEFT JOIN result.

    – jarlh
    Mar 7 at 8:16

















  • I tried left and right join, still doesn’t work

    – tirth96
    Mar 7 at 6:57











  • @tirth96 create table here in fiddle dbfiddle.uk/… it should work if not then you need to help us by creating fiddle then we can solve your problem

    – Zaynul Abadin Tuhin
    Mar 7 at 6:58












  • ok nvm this worked, do you know it can be done with just join, not left join

    – tirth96
    Mar 7 at 7:08











  • @tirth96 it will not work just by using join because with out left join you will loose the country from where still not ordered place

    – Zaynul Abadin Tuhin
    Mar 7 at 7:12






  • 1





    That LEFT JOIN returns regular INNER JOIN result. Move the orders.date conditions from WHERE to ON to get true LEFT JOIN result.

    – jarlh
    Mar 7 at 8:16
















I tried left and right join, still doesn’t work

– tirth96
Mar 7 at 6:57





I tried left and right join, still doesn’t work

– tirth96
Mar 7 at 6:57













@tirth96 create table here in fiddle dbfiddle.uk/… it should work if not then you need to help us by creating fiddle then we can solve your problem

– Zaynul Abadin Tuhin
Mar 7 at 6:58






@tirth96 create table here in fiddle dbfiddle.uk/… it should work if not then you need to help us by creating fiddle then we can solve your problem

– Zaynul Abadin Tuhin
Mar 7 at 6:58














ok nvm this worked, do you know it can be done with just join, not left join

– tirth96
Mar 7 at 7:08





ok nvm this worked, do you know it can be done with just join, not left join

– tirth96
Mar 7 at 7:08













@tirth96 it will not work just by using join because with out left join you will loose the country from where still not ordered place

– Zaynul Abadin Tuhin
Mar 7 at 7:12





@tirth96 it will not work just by using join because with out left join you will loose the country from where still not ordered place

– Zaynul Abadin Tuhin
Mar 7 at 7:12




1




1





That LEFT JOIN returns regular INNER JOIN result. Move the orders.date conditions from WHERE to ON to get true LEFT JOIN result.

– jarlh
Mar 7 at 8:16





That LEFT JOIN returns regular INNER JOIN result. Move the orders.date conditions from WHERE to ON to get true LEFT JOIN result.

– jarlh
Mar 7 at 8:16













2














use left join and move your where condition in ON clause



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by country





share|improve this answer























  • Tried that, still no luck

    – tirth96
    Mar 7 at 6:58






  • 1





    @tirth96: that should do exactly what you want. You need to edit and provide some sample data and the expected output on that data. Or create a short online example, e.g. here or here

    – a_horse_with_no_name
    Mar 7 at 7:07












  • ooh i see, this worked!

    – tirth96
    Mar 7 at 7:09











  • Do you know how I can do the same thing with just join?

    – tirth96
    Mar 7 at 7:09











  • @tirth96, you've to use left join - with inner join it's not possible

    – fa06
    Mar 7 at 7:10















2














use left join and move your where condition in ON clause



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by country





share|improve this answer























  • Tried that, still no luck

    – tirth96
    Mar 7 at 6:58






  • 1





    @tirth96: that should do exactly what you want. You need to edit and provide some sample data and the expected output on that data. Or create a short online example, e.g. here or here

    – a_horse_with_no_name
    Mar 7 at 7:07












  • ooh i see, this worked!

    – tirth96
    Mar 7 at 7:09











  • Do you know how I can do the same thing with just join?

    – tirth96
    Mar 7 at 7:09











  • @tirth96, you've to use left join - with inner join it's not possible

    – fa06
    Mar 7 at 7:10













2












2








2







use left join and move your where condition in ON clause



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by country





share|improve this answer













use left join and move your where condition in ON clause



select country, count(orders.id) 
from customers left join orders
on customers.id = orders.id and orders.date >= '2018-01-01' and
orders.date <='2018-12-31'
group by country






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 6:49









fa06fa06

16.2k21018




16.2k21018












  • Tried that, still no luck

    – tirth96
    Mar 7 at 6:58






  • 1





    @tirth96: that should do exactly what you want. You need to edit and provide some sample data and the expected output on that data. Or create a short online example, e.g. here or here

    – a_horse_with_no_name
    Mar 7 at 7:07












  • ooh i see, this worked!

    – tirth96
    Mar 7 at 7:09











  • Do you know how I can do the same thing with just join?

    – tirth96
    Mar 7 at 7:09











  • @tirth96, you've to use left join - with inner join it's not possible

    – fa06
    Mar 7 at 7:10

















  • Tried that, still no luck

    – tirth96
    Mar 7 at 6:58






  • 1





    @tirth96: that should do exactly what you want. You need to edit and provide some sample data and the expected output on that data. Or create a short online example, e.g. here or here

    – a_horse_with_no_name
    Mar 7 at 7:07












  • ooh i see, this worked!

    – tirth96
    Mar 7 at 7:09











  • Do you know how I can do the same thing with just join?

    – tirth96
    Mar 7 at 7:09











  • @tirth96, you've to use left join - with inner join it's not possible

    – fa06
    Mar 7 at 7:10
















Tried that, still no luck

– tirth96
Mar 7 at 6:58





Tried that, still no luck

– tirth96
Mar 7 at 6:58




1




1





@tirth96: that should do exactly what you want. You need to edit and provide some sample data and the expected output on that data. Or create a short online example, e.g. here or here

– a_horse_with_no_name
Mar 7 at 7:07






@tirth96: that should do exactly what you want. You need to edit and provide some sample data and the expected output on that data. Or create a short online example, e.g. here or here

– a_horse_with_no_name
Mar 7 at 7:07














ooh i see, this worked!

– tirth96
Mar 7 at 7:09





ooh i see, this worked!

– tirth96
Mar 7 at 7:09













Do you know how I can do the same thing with just join?

– tirth96
Mar 7 at 7:09





Do you know how I can do the same thing with just join?

– tirth96
Mar 7 at 7:09













@tirth96, you've to use left join - with inner join it's not possible

– fa06
Mar 7 at 7:10





@tirth96, you've to use left join - with inner join it's not possible

– fa06
Mar 7 at 7:10

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037647%2fpostgresql-row-not-shown-when-count-is-zero%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme