How to get the number of reservations for each customer for the below tableMySQL Error 1093 - Can't specify target table for update in FROM clauseCan I concatenate multiple MySQL rows into one field?How do I specify unique constraint for multiple columns in MySQL?How to get a list of MySQL user accountsHost 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL serverMySQL - Get row number on selectHow do I escape reserved words used as column names? MySQL/Create TableCreate a temporary table in a SELECT statement without a separate CREATE TABLEHow to get the sizes of the tables of a MySQL database?Reference - What does this error mean in PHP?

A Journey Through Space and Time

What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?

New order #4: World

What is the meaning of "of trouble" in the following sentence?

Concept of linear mappings are confusing me

How does one intimidate enemies without having the capacity for violence?

Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?

How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

How old can references or sources in a thesis be?

I see my dog run

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

Is there really no realistic way for a skeleton monster to move around without magic?

What Brexit solution does the DUP want?

How to calculate implied correlation via observed market price (Margrabe option)

What would the Romans have called "sorcery"?

Patience, young "Padovan"

Banach space and Hilbert space topology

XeLaTeX and pdfLaTeX ignore hyphenation

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

My colleague's body is amazing

What do you call a Matrix-like slowdown and camera movement effect?

Why is the design of haulage companies so “special”?

Are white and non-white police officers equally likely to kill black suspects?



How to get the number of reservations for each customer for the below table


MySQL Error 1093 - Can't specify target table for update in FROM clauseCan I concatenate multiple MySQL rows into one field?How do I specify unique constraint for multiple columns in MySQL?How to get a list of MySQL user accountsHost 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL serverMySQL - Get row number on selectHow do I escape reserved words used as column names? MySQL/Create TableCreate a temporary table in a SELECT statement without a separate CREATE TABLEHow to get the sizes of the tables of a MySQL database?Reference - What does this error mean in PHP?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have two tables and i just want to know how to get the number of reservations for each customer for the below table.



Thank you for your support.



How to get the number of reservations for each customer for the below table.










share|improve this question

















  • 2





    What code have you tried? We are happy to help you troubleshoot, but we aren't a code writing service. We expect that you at least make an effort to answer the question yourself.

    – Jane
    Mar 22 at 1:03

















0















I have two tables and i just want to know how to get the number of reservations for each customer for the below table.



Thank you for your support.



How to get the number of reservations for each customer for the below table.










share|improve this question

















  • 2





    What code have you tried? We are happy to help you troubleshoot, but we aren't a code writing service. We expect that you at least make an effort to answer the question yourself.

    – Jane
    Mar 22 at 1:03













0












0








0








I have two tables and i just want to know how to get the number of reservations for each customer for the below table.



Thank you for your support.



How to get the number of reservations for each customer for the below table.










share|improve this question














I have two tables and i just want to know how to get the number of reservations for each customer for the below table.



Thank you for your support.



How to get the number of reservations for each customer for the below table.







mysql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 1:02









rook12320rook12320

85




85







  • 2





    What code have you tried? We are happy to help you troubleshoot, but we aren't a code writing service. We expect that you at least make an effort to answer the question yourself.

    – Jane
    Mar 22 at 1:03












  • 2





    What code have you tried? We are happy to help you troubleshoot, but we aren't a code writing service. We expect that you at least make an effort to answer the question yourself.

    – Jane
    Mar 22 at 1:03







2




2





What code have you tried? We are happy to help you troubleshoot, but we aren't a code writing service. We expect that you at least make an effort to answer the question yourself.

– Jane
Mar 22 at 1:03





What code have you tried? We are happy to help you troubleshoot, but we aren't a code writing service. We expect that you at least make an effort to answer the question yourself.

– Jane
Mar 22 at 1:03












1 Answer
1






active

oldest

votes


















0














You could use a group by query:



select customer.customer_id from customer, count(customer.customer_id) as reservation_count
from customer
left join reservation on reservation.customer_customer_id = customer.customer_id
group by customer.customer_id


In this case a left join is used to include customers that don't have any reservations and should have a reservation_count of 0. Customers with reservations will have a reservation_count greater than 0.






share|improve this answer

























  • Thank you for your collaboration I tried to use this but there is an error after as SELECT customer.customer_id FROM customer, COUNT * AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id

    – rook12320
    Mar 22 at 1:16












  • I also tryed to remove the * after COUNT but doesn't work

    – rook12320
    Mar 22 at 1:19











  • Interesting, can you post the full error?

    – jspcal
    Mar 22 at 1:22











  • I tryed this code also BUT still also SELECT customer.customer_id FROM customer JOIN reservation, COUNT AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id WHERE reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id here is the error #1066 - Not unique table/alias: 'reservation'

    – rook12320
    Mar 22 at 1:27












  • I think it should be reservation table because we need the total number of reservation for each customer. what is your advise

    – rook12320
    Mar 22 at 1:30











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%2f55291421%2fhow-to-get-the-number-of-reservations-for-each-customer-for-the-below-table%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You could use a group by query:



select customer.customer_id from customer, count(customer.customer_id) as reservation_count
from customer
left join reservation on reservation.customer_customer_id = customer.customer_id
group by customer.customer_id


In this case a left join is used to include customers that don't have any reservations and should have a reservation_count of 0. Customers with reservations will have a reservation_count greater than 0.






share|improve this answer

























  • Thank you for your collaboration I tried to use this but there is an error after as SELECT customer.customer_id FROM customer, COUNT * AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id

    – rook12320
    Mar 22 at 1:16












  • I also tryed to remove the * after COUNT but doesn't work

    – rook12320
    Mar 22 at 1:19











  • Interesting, can you post the full error?

    – jspcal
    Mar 22 at 1:22











  • I tryed this code also BUT still also SELECT customer.customer_id FROM customer JOIN reservation, COUNT AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id WHERE reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id here is the error #1066 - Not unique table/alias: 'reservation'

    – rook12320
    Mar 22 at 1:27












  • I think it should be reservation table because we need the total number of reservation for each customer. what is your advise

    – rook12320
    Mar 22 at 1:30















0














You could use a group by query:



select customer.customer_id from customer, count(customer.customer_id) as reservation_count
from customer
left join reservation on reservation.customer_customer_id = customer.customer_id
group by customer.customer_id


In this case a left join is used to include customers that don't have any reservations and should have a reservation_count of 0. Customers with reservations will have a reservation_count greater than 0.






share|improve this answer

























  • Thank you for your collaboration I tried to use this but there is an error after as SELECT customer.customer_id FROM customer, COUNT * AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id

    – rook12320
    Mar 22 at 1:16












  • I also tryed to remove the * after COUNT but doesn't work

    – rook12320
    Mar 22 at 1:19











  • Interesting, can you post the full error?

    – jspcal
    Mar 22 at 1:22











  • I tryed this code also BUT still also SELECT customer.customer_id FROM customer JOIN reservation, COUNT AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id WHERE reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id here is the error #1066 - Not unique table/alias: 'reservation'

    – rook12320
    Mar 22 at 1:27












  • I think it should be reservation table because we need the total number of reservation for each customer. what is your advise

    – rook12320
    Mar 22 at 1:30













0












0








0







You could use a group by query:



select customer.customer_id from customer, count(customer.customer_id) as reservation_count
from customer
left join reservation on reservation.customer_customer_id = customer.customer_id
group by customer.customer_id


In this case a left join is used to include customers that don't have any reservations and should have a reservation_count of 0. Customers with reservations will have a reservation_count greater than 0.






share|improve this answer















You could use a group by query:



select customer.customer_id from customer, count(customer.customer_id) as reservation_count
from customer
left join reservation on reservation.customer_customer_id = customer.customer_id
group by customer.customer_id


In this case a left join is used to include customers that don't have any reservations and should have a reservation_count of 0. Customers with reservations will have a reservation_count greater than 0.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 1:22

























answered Mar 22 at 1:07









jspcaljspcal

40.2k45264




40.2k45264












  • Thank you for your collaboration I tried to use this but there is an error after as SELECT customer.customer_id FROM customer, COUNT * AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id

    – rook12320
    Mar 22 at 1:16












  • I also tryed to remove the * after COUNT but doesn't work

    – rook12320
    Mar 22 at 1:19











  • Interesting, can you post the full error?

    – jspcal
    Mar 22 at 1:22











  • I tryed this code also BUT still also SELECT customer.customer_id FROM customer JOIN reservation, COUNT AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id WHERE reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id here is the error #1066 - Not unique table/alias: 'reservation'

    – rook12320
    Mar 22 at 1:27












  • I think it should be reservation table because we need the total number of reservation for each customer. what is your advise

    – rook12320
    Mar 22 at 1:30

















  • Thank you for your collaboration I tried to use this but there is an error after as SELECT customer.customer_id FROM customer, COUNT * AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id

    – rook12320
    Mar 22 at 1:16












  • I also tryed to remove the * after COUNT but doesn't work

    – rook12320
    Mar 22 at 1:19











  • Interesting, can you post the full error?

    – jspcal
    Mar 22 at 1:22











  • I tryed this code also BUT still also SELECT customer.customer_id FROM customer JOIN reservation, COUNT AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id WHERE reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id here is the error #1066 - Not unique table/alias: 'reservation'

    – rook12320
    Mar 22 at 1:27












  • I think it should be reservation table because we need the total number of reservation for each customer. what is your advise

    – rook12320
    Mar 22 at 1:30
















Thank you for your collaboration I tried to use this but there is an error after as SELECT customer.customer_id FROM customer, COUNT * AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id

– rook12320
Mar 22 at 1:16






Thank you for your collaboration I tried to use this but there is an error after as SELECT customer.customer_id FROM customer, COUNT * AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id

– rook12320
Mar 22 at 1:16














I also tryed to remove the * after COUNT but doesn't work

– rook12320
Mar 22 at 1:19





I also tryed to remove the * after COUNT but doesn't work

– rook12320
Mar 22 at 1:19













Interesting, can you post the full error?

– jspcal
Mar 22 at 1:22





Interesting, can you post the full error?

– jspcal
Mar 22 at 1:22













I tryed this code also BUT still also SELECT customer.customer_id FROM customer JOIN reservation, COUNT AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id WHERE reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id here is the error #1066 - Not unique table/alias: 'reservation'

– rook12320
Mar 22 at 1:27






I tryed this code also BUT still also SELECT customer.customer_id FROM customer JOIN reservation, COUNT AS reservation_count LEFT JOIN reservation ON reservation.customer_customer_id = customer.customer_id WHERE reservation.customer_customer_id = customer.customer_id GROUP BY customer.customer_id here is the error #1066 - Not unique table/alias: 'reservation'

– rook12320
Mar 22 at 1:27














I think it should be reservation table because we need the total number of reservation for each customer. what is your advise

– rook12320
Mar 22 at 1:30





I think it should be reservation table because we need the total number of reservation for each customer. what is your advise

– rook12320
Mar 22 at 1:30



















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%2f55291421%2fhow-to-get-the-number-of-reservations-for-each-customer-for-the-below-table%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현