How to select count() if there is a value but select nothing if the value is 0How does database indexing work?Insert into … values ( SELECT … FROM … )How can I prevent SQL injection in PHP?How do I perform an IF…THEN in an SQL SELECT?Add a column with a default value to an existing table in SQL ServerHow do I UPDATE from a SELECT in SQL Server?Finding duplicate values in a SQL table'IF' in 'SELECT' statement - choose output value based on column valuesSQL select only rows with max value on a columnHow to import an SQL file using the command line in MySQL?
Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?
What dog breeds survive the apocalypse for generations?
Was the dragon prowess intentionally downplayed in S08E04?
Failing students when it might cause them economic ruin
Can I pay my credit card?
What kind of environment would favor hermaphroditism in a sentient species over regular, old sexes?
Canadian citizen who is presently in litigation with a US-based company
How can we delete item permanently without storing in Recycle Bin?
Cannot remove door knob -- totally inaccessible!
A latin word for "area of interest"
Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?
Is it standard to have the first week's pay indefinitely withheld?
How to handle professionally if colleagues has referred his relative and asking to take easy while taking interview
Why does the U.S military use mercenaries?
Does a non-singular matrix have a large minor with disjoint rows and columns and full rank?
Cuban Primes
How to add support of several unicode letters inside a document?
Find the area of the rectangle
Do we see some Unsullied doing this in S08E05?
Using 何 with the general counter ~つ
When did Britain learn about American independence?
How can the noun "moyen" be used to denote the meaning "they still don't stop complaining"?
Would it be fair to use 1d30 (instead of rolling 2d20 and taking the higher die) for advantage rolls?
How does Heat Metal interact with a follow-up Frostbite?
How to select count() if there is a value but select nothing if the value is 0
How does database indexing work?Insert into … values ( SELECT … FROM … )How can I prevent SQL injection in PHP?How do I perform an IF…THEN in an SQL SELECT?Add a column with a default value to an existing table in SQL ServerHow do I UPDATE from a SELECT in SQL Server?Finding duplicate values in a SQL table'IF' in 'SELECT' statement - choose output value based on column valuesSQL select only rows with max value on a columnHow to import an SQL file using the command line in MySQL?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Im writing a booking system for a project and currently working on getting some report functionality built in. I need to return a list of all classes on todays date regardless of wether they have a booking or not.
The problem i am getting is when there are no bookings, i dont get anything back from the sql query but when there are bookings, i get the correct information. If i take the count for the bookings away from the select then everything works however i need all of this info.
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM
`computing-project`.class_instances class_instances,
`computing-project`.classes classes,
`computing-project`.users users,
`computing-project`.bookings bookings
WHERE
DATE(class_instances.instance_sdate) = DATE(NOW()) AND
class_instances.class_id = classes.class_id AND
classes.teacher_id = users.user_id AND
bookings.instance_id = class_instances.instance_id
Data set : https://imgur.com/JDjkK0G
This code above works only when someone has booked the class. not when the class has no booked members.
i still get the count returned as 0 but no other results for the other columns
- hope this makes sense.
Expected Output
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| instance_sdate | class_name | class_max | user_name_first | user_name_last | count(bookings.booking_id) |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| 2019-03-23 16:38:00.0 | Test | 11 | Louis | Simpson | 0 |
| 2019-03-23 16:39:00.0 | Test2 | 12 | Louis | Simpson | 0 |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
mysql sql mysql-python
|
show 1 more comment
Im writing a booking system for a project and currently working on getting some report functionality built in. I need to return a list of all classes on todays date regardless of wether they have a booking or not.
The problem i am getting is when there are no bookings, i dont get anything back from the sql query but when there are bookings, i get the correct information. If i take the count for the bookings away from the select then everything works however i need all of this info.
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM
`computing-project`.class_instances class_instances,
`computing-project`.classes classes,
`computing-project`.users users,
`computing-project`.bookings bookings
WHERE
DATE(class_instances.instance_sdate) = DATE(NOW()) AND
class_instances.class_id = classes.class_id AND
classes.teacher_id = users.user_id AND
bookings.instance_id = class_instances.instance_id
Data set : https://imgur.com/JDjkK0G
This code above works only when someone has booked the class. not when the class has no booked members.
i still get the count returned as 0 but no other results for the other columns
- hope this makes sense.
Expected Output
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| instance_sdate | class_name | class_max | user_name_first | user_name_last | count(bookings.booking_id) |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| 2019-03-23 16:38:00.0 | Test | 11 | Louis | Simpson | 0 |
| 2019-03-23 16:39:00.0 | Test2 | 12 | Louis | Simpson | 0 |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
mysql sql mysql-python
2
Never use commas in theFROMclause. Always use proper, explicit, standardJOINsyntax.
– Gordon Linoff
Mar 23 at 16:22
Hoestly, im quite new to sql with the join syntax, do you know how i would convert this to join ?
– Lksimo
Mar 23 at 16:28
i still get the count returned as 0 but no other results for the other columns What other results should there be if there are no bookings?
– forpas
Mar 23 at 16:33
@Lksimo . . . You shouldn't even be learning to use commas in theFROMclause. You should only learningJOIN. There are many resources on and off line to learn SQL.
– Gordon Linoff
Mar 23 at 17:00
Welcome to Stack Overflow. I realize you're new to the site so if I may I'll offer a couple of suggestions. First, your question was actually pretty good - but please don't post sample data as an image. Instead, include it in the question as text so that people can use it without having to retype everything - which most of us aren't going to do. Second, and even better, would be to go to an SQL test site such as sqlfiddle.com or dbfiddle.uk, set up your tables and populate them with data, and then people can work with it to help find a solution to your problem. Best of luck.
– Bob Jarvis
Mar 24 at 15:31
|
show 1 more comment
Im writing a booking system for a project and currently working on getting some report functionality built in. I need to return a list of all classes on todays date regardless of wether they have a booking or not.
The problem i am getting is when there are no bookings, i dont get anything back from the sql query but when there are bookings, i get the correct information. If i take the count for the bookings away from the select then everything works however i need all of this info.
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM
`computing-project`.class_instances class_instances,
`computing-project`.classes classes,
`computing-project`.users users,
`computing-project`.bookings bookings
WHERE
DATE(class_instances.instance_sdate) = DATE(NOW()) AND
class_instances.class_id = classes.class_id AND
classes.teacher_id = users.user_id AND
bookings.instance_id = class_instances.instance_id
Data set : https://imgur.com/JDjkK0G
This code above works only when someone has booked the class. not when the class has no booked members.
i still get the count returned as 0 but no other results for the other columns
- hope this makes sense.
Expected Output
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| instance_sdate | class_name | class_max | user_name_first | user_name_last | count(bookings.booking_id) |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| 2019-03-23 16:38:00.0 | Test | 11 | Louis | Simpson | 0 |
| 2019-03-23 16:39:00.0 | Test2 | 12 | Louis | Simpson | 0 |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
mysql sql mysql-python
Im writing a booking system for a project and currently working on getting some report functionality built in. I need to return a list of all classes on todays date regardless of wether they have a booking or not.
The problem i am getting is when there are no bookings, i dont get anything back from the sql query but when there are bookings, i get the correct information. If i take the count for the bookings away from the select then everything works however i need all of this info.
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM
`computing-project`.class_instances class_instances,
`computing-project`.classes classes,
`computing-project`.users users,
`computing-project`.bookings bookings
WHERE
DATE(class_instances.instance_sdate) = DATE(NOW()) AND
class_instances.class_id = classes.class_id AND
classes.teacher_id = users.user_id AND
bookings.instance_id = class_instances.instance_id
Data set : https://imgur.com/JDjkK0G
This code above works only when someone has booked the class. not when the class has no booked members.
i still get the count returned as 0 but no other results for the other columns
- hope this makes sense.
Expected Output
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| instance_sdate | class_name | class_max | user_name_first | user_name_last | count(bookings.booking_id) |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
| 2019-03-23 16:38:00.0 | Test | 11 | Louis | Simpson | 0 |
| 2019-03-23 16:39:00.0 | Test2 | 12 | Louis | Simpson | 0 |
+-----------------------+------------+-----------+-----------------+----------------+----------------------------+
mysql sql mysql-python
mysql sql mysql-python
edited Mar 24 at 12:36
Lksimo
asked Mar 23 at 16:22
LksimoLksimo
33
33
2
Never use commas in theFROMclause. Always use proper, explicit, standardJOINsyntax.
– Gordon Linoff
Mar 23 at 16:22
Hoestly, im quite new to sql with the join syntax, do you know how i would convert this to join ?
– Lksimo
Mar 23 at 16:28
i still get the count returned as 0 but no other results for the other columns What other results should there be if there are no bookings?
– forpas
Mar 23 at 16:33
@Lksimo . . . You shouldn't even be learning to use commas in theFROMclause. You should only learningJOIN. There are many resources on and off line to learn SQL.
– Gordon Linoff
Mar 23 at 17:00
Welcome to Stack Overflow. I realize you're new to the site so if I may I'll offer a couple of suggestions. First, your question was actually pretty good - but please don't post sample data as an image. Instead, include it in the question as text so that people can use it without having to retype everything - which most of us aren't going to do. Second, and even better, would be to go to an SQL test site such as sqlfiddle.com or dbfiddle.uk, set up your tables and populate them with data, and then people can work with it to help find a solution to your problem. Best of luck.
– Bob Jarvis
Mar 24 at 15:31
|
show 1 more comment
2
Never use commas in theFROMclause. Always use proper, explicit, standardJOINsyntax.
– Gordon Linoff
Mar 23 at 16:22
Hoestly, im quite new to sql with the join syntax, do you know how i would convert this to join ?
– Lksimo
Mar 23 at 16:28
i still get the count returned as 0 but no other results for the other columns What other results should there be if there are no bookings?
– forpas
Mar 23 at 16:33
@Lksimo . . . You shouldn't even be learning to use commas in theFROMclause. You should only learningJOIN. There are many resources on and off line to learn SQL.
– Gordon Linoff
Mar 23 at 17:00
Welcome to Stack Overflow. I realize you're new to the site so if I may I'll offer a couple of suggestions. First, your question was actually pretty good - but please don't post sample data as an image. Instead, include it in the question as text so that people can use it without having to retype everything - which most of us aren't going to do. Second, and even better, would be to go to an SQL test site such as sqlfiddle.com or dbfiddle.uk, set up your tables and populate them with data, and then people can work with it to help find a solution to your problem. Best of luck.
– Bob Jarvis
Mar 24 at 15:31
2
2
Never use commas in the
FROM clause. Always use proper, explicit, standard JOIN syntax.– Gordon Linoff
Mar 23 at 16:22
Never use commas in the
FROM clause. Always use proper, explicit, standard JOIN syntax.– Gordon Linoff
Mar 23 at 16:22
Hoestly, im quite new to sql with the join syntax, do you know how i would convert this to join ?
– Lksimo
Mar 23 at 16:28
Hoestly, im quite new to sql with the join syntax, do you know how i would convert this to join ?
– Lksimo
Mar 23 at 16:28
i still get the count returned as 0 but no other results for the other columns What other results should there be if there are no bookings?
– forpas
Mar 23 at 16:33
i still get the count returned as 0 but no other results for the other columns What other results should there be if there are no bookings?
– forpas
Mar 23 at 16:33
@Lksimo . . . You shouldn't even be learning to use commas in the
FROM clause. You should only learning JOIN. There are many resources on and off line to learn SQL.– Gordon Linoff
Mar 23 at 17:00
@Lksimo . . . You shouldn't even be learning to use commas in the
FROM clause. You should only learning JOIN. There are many resources on and off line to learn SQL.– Gordon Linoff
Mar 23 at 17:00
Welcome to Stack Overflow. I realize you're new to the site so if I may I'll offer a couple of suggestions. First, your question was actually pretty good - but please don't post sample data as an image. Instead, include it in the question as text so that people can use it without having to retype everything - which most of us aren't going to do. Second, and even better, would be to go to an SQL test site such as sqlfiddle.com or dbfiddle.uk, set up your tables and populate them with data, and then people can work with it to help find a solution to your problem. Best of luck.
– Bob Jarvis
Mar 24 at 15:31
Welcome to Stack Overflow. I realize you're new to the site so if I may I'll offer a couple of suggestions. First, your question was actually pretty good - but please don't post sample data as an image. Instead, include it in the question as text so that people can use it without having to retype everything - which most of us aren't going to do. Second, and even better, would be to go to an SQL test site such as sqlfiddle.com or dbfiddle.uk, set up your tables and populate them with data, and then people can work with it to help find a solution to your problem. Best of luck.
– Bob Jarvis
Mar 24 at 15:31
|
show 1 more comment
1 Answer
1
active
oldest
votes
If you want also the not booking the you need a left join (outer) join
you should avoid old implicit join sintax based on where, you should use explicit join sintax and using this use left join for booking
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM `computing-project`.class_instances class_instances
INNER JOIN `computing-project`.classes classes ON class_instances.class_id = classes.class_id
INNER JOIN `computing-project`.users users ON classes.teacher_id = users.user_id
LEFT JOIN `computing-project`.bookings bookings ON bookings.instance_id = class_instances.instance_id
WHERE DATE(class_instances.instance_sdate) = DATE(NOW())
GROUP BY class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last
This returned information for each of the fields when there were no bookings like i needed however it only returned one instance and there are two in the DB for today ?
– Lksimo
Mar 23 at 16:45
I'm not in your data ... so update your question ..add a proper (clear) data sample . and the expected result .as tabular text
– scaisEdge
Mar 23 at 17:00
Added an image of the data set, i also got this from your query - imgur.com/R5sePQg Thanks for helping
– Lksimo
Mar 23 at 17:30
I don't see ... your expected result ????? .. .. i can't image your goal
– scaisEdge
Mar 23 at 17:36
Okay maybe i didnt explain well enough, im quite new to this in terms of posting on stackoverflow. Essentially i have a bunch of classes (class.instances) and i want to display all of the classes and their info that occur today. Along with that, i need to see a total of how many people are booked on the class which is calculated from the number of bookings for that instance id
– Lksimo
Mar 24 at 11:58
|
show 5 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315841%2fhow-to-select-count-if-there-is-a-value-but-select-nothing-if-the-value-is-0%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
If you want also the not booking the you need a left join (outer) join
you should avoid old implicit join sintax based on where, you should use explicit join sintax and using this use left join for booking
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM `computing-project`.class_instances class_instances
INNER JOIN `computing-project`.classes classes ON class_instances.class_id = classes.class_id
INNER JOIN `computing-project`.users users ON classes.teacher_id = users.user_id
LEFT JOIN `computing-project`.bookings bookings ON bookings.instance_id = class_instances.instance_id
WHERE DATE(class_instances.instance_sdate) = DATE(NOW())
GROUP BY class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last
This returned information for each of the fields when there were no bookings like i needed however it only returned one instance and there are two in the DB for today ?
– Lksimo
Mar 23 at 16:45
I'm not in your data ... so update your question ..add a proper (clear) data sample . and the expected result .as tabular text
– scaisEdge
Mar 23 at 17:00
Added an image of the data set, i also got this from your query - imgur.com/R5sePQg Thanks for helping
– Lksimo
Mar 23 at 17:30
I don't see ... your expected result ????? .. .. i can't image your goal
– scaisEdge
Mar 23 at 17:36
Okay maybe i didnt explain well enough, im quite new to this in terms of posting on stackoverflow. Essentially i have a bunch of classes (class.instances) and i want to display all of the classes and their info that occur today. Along with that, i need to see a total of how many people are booked on the class which is calculated from the number of bookings for that instance id
– Lksimo
Mar 24 at 11:58
|
show 5 more comments
If you want also the not booking the you need a left join (outer) join
you should avoid old implicit join sintax based on where, you should use explicit join sintax and using this use left join for booking
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM `computing-project`.class_instances class_instances
INNER JOIN `computing-project`.classes classes ON class_instances.class_id = classes.class_id
INNER JOIN `computing-project`.users users ON classes.teacher_id = users.user_id
LEFT JOIN `computing-project`.bookings bookings ON bookings.instance_id = class_instances.instance_id
WHERE DATE(class_instances.instance_sdate) = DATE(NOW())
GROUP BY class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last
This returned information for each of the fields when there were no bookings like i needed however it only returned one instance and there are two in the DB for today ?
– Lksimo
Mar 23 at 16:45
I'm not in your data ... so update your question ..add a proper (clear) data sample . and the expected result .as tabular text
– scaisEdge
Mar 23 at 17:00
Added an image of the data set, i also got this from your query - imgur.com/R5sePQg Thanks for helping
– Lksimo
Mar 23 at 17:30
I don't see ... your expected result ????? .. .. i can't image your goal
– scaisEdge
Mar 23 at 17:36
Okay maybe i didnt explain well enough, im quite new to this in terms of posting on stackoverflow. Essentially i have a bunch of classes (class.instances) and i want to display all of the classes and their info that occur today. Along with that, i need to see a total of how many people are booked on the class which is calculated from the number of bookings for that instance id
– Lksimo
Mar 24 at 11:58
|
show 5 more comments
If you want also the not booking the you need a left join (outer) join
you should avoid old implicit join sintax based on where, you should use explicit join sintax and using this use left join for booking
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM `computing-project`.class_instances class_instances
INNER JOIN `computing-project`.classes classes ON class_instances.class_id = classes.class_id
INNER JOIN `computing-project`.users users ON classes.teacher_id = users.user_id
LEFT JOIN `computing-project`.bookings bookings ON bookings.instance_id = class_instances.instance_id
WHERE DATE(class_instances.instance_sdate) = DATE(NOW())
GROUP BY class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last
If you want also the not booking the you need a left join (outer) join
you should avoid old implicit join sintax based on where, you should use explicit join sintax and using this use left join for booking
SELECT
class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last,
COUNT(bookings.booking_id)
FROM `computing-project`.class_instances class_instances
INNER JOIN `computing-project`.classes classes ON class_instances.class_id = classes.class_id
INNER JOIN `computing-project`.users users ON classes.teacher_id = users.user_id
LEFT JOIN `computing-project`.bookings bookings ON bookings.instance_id = class_instances.instance_id
WHERE DATE(class_instances.instance_sdate) = DATE(NOW())
GROUP BY class_instances.instance_sdate,
classes.class_name,
classes.class_max,
users.user_name_first,
users.user_name_last
edited Mar 24 at 15:15
answered Mar 23 at 16:32
scaisEdgescaisEdge
101k105372
101k105372
This returned information for each of the fields when there were no bookings like i needed however it only returned one instance and there are two in the DB for today ?
– Lksimo
Mar 23 at 16:45
I'm not in your data ... so update your question ..add a proper (clear) data sample . and the expected result .as tabular text
– scaisEdge
Mar 23 at 17:00
Added an image of the data set, i also got this from your query - imgur.com/R5sePQg Thanks for helping
– Lksimo
Mar 23 at 17:30
I don't see ... your expected result ????? .. .. i can't image your goal
– scaisEdge
Mar 23 at 17:36
Okay maybe i didnt explain well enough, im quite new to this in terms of posting on stackoverflow. Essentially i have a bunch of classes (class.instances) and i want to display all of the classes and their info that occur today. Along with that, i need to see a total of how many people are booked on the class which is calculated from the number of bookings for that instance id
– Lksimo
Mar 24 at 11:58
|
show 5 more comments
This returned information for each of the fields when there were no bookings like i needed however it only returned one instance and there are two in the DB for today ?
– Lksimo
Mar 23 at 16:45
I'm not in your data ... so update your question ..add a proper (clear) data sample . and the expected result .as tabular text
– scaisEdge
Mar 23 at 17:00
Added an image of the data set, i also got this from your query - imgur.com/R5sePQg Thanks for helping
– Lksimo
Mar 23 at 17:30
I don't see ... your expected result ????? .. .. i can't image your goal
– scaisEdge
Mar 23 at 17:36
Okay maybe i didnt explain well enough, im quite new to this in terms of posting on stackoverflow. Essentially i have a bunch of classes (class.instances) and i want to display all of the classes and their info that occur today. Along with that, i need to see a total of how many people are booked on the class which is calculated from the number of bookings for that instance id
– Lksimo
Mar 24 at 11:58
This returned information for each of the fields when there were no bookings like i needed however it only returned one instance and there are two in the DB for today ?
– Lksimo
Mar 23 at 16:45
This returned information for each of the fields when there were no bookings like i needed however it only returned one instance and there are two in the DB for today ?
– Lksimo
Mar 23 at 16:45
I'm not in your data ... so update your question ..add a proper (clear) data sample . and the expected result .as tabular text
– scaisEdge
Mar 23 at 17:00
I'm not in your data ... so update your question ..add a proper (clear) data sample . and the expected result .as tabular text
– scaisEdge
Mar 23 at 17:00
Added an image of the data set, i also got this from your query - imgur.com/R5sePQg Thanks for helping
– Lksimo
Mar 23 at 17:30
Added an image of the data set, i also got this from your query - imgur.com/R5sePQg Thanks for helping
– Lksimo
Mar 23 at 17:30
I don't see ... your expected result ????? .. .. i can't image your goal
– scaisEdge
Mar 23 at 17:36
I don't see ... your expected result ????? .. .. i can't image your goal
– scaisEdge
Mar 23 at 17:36
Okay maybe i didnt explain well enough, im quite new to this in terms of posting on stackoverflow. Essentially i have a bunch of classes (class.instances) and i want to display all of the classes and their info that occur today. Along with that, i need to see a total of how many people are booked on the class which is calculated from the number of bookings for that instance id
– Lksimo
Mar 24 at 11:58
Okay maybe i didnt explain well enough, im quite new to this in terms of posting on stackoverflow. Essentially i have a bunch of classes (class.instances) and i want to display all of the classes and their info that occur today. Along with that, i need to see a total of how many people are booked on the class which is calculated from the number of bookings for that instance id
– Lksimo
Mar 24 at 11:58
|
show 5 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315841%2fhow-to-select-count-if-there-is-a-value-but-select-nothing-if-the-value-is-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Never use commas in the
FROMclause. Always use proper, explicit, standardJOINsyntax.– Gordon Linoff
Mar 23 at 16:22
Hoestly, im quite new to sql with the join syntax, do you know how i would convert this to join ?
– Lksimo
Mar 23 at 16:28
i still get the count returned as 0 but no other results for the other columns What other results should there be if there are no bookings?
– forpas
Mar 23 at 16:33
@Lksimo . . . You shouldn't even be learning to use commas in the
FROMclause. You should only learningJOIN. There are many resources on and off line to learn SQL.– Gordon Linoff
Mar 23 at 17:00
Welcome to Stack Overflow. I realize you're new to the site so if I may I'll offer a couple of suggestions. First, your question was actually pretty good - but please don't post sample data as an image. Instead, include it in the question as text so that people can use it without having to retype everything - which most of us aren't going to do. Second, and even better, would be to go to an SQL test site such as sqlfiddle.com or dbfiddle.uk, set up your tables and populate them with data, and then people can work with it to help find a solution to your problem. Best of luck.
– Bob Jarvis
Mar 24 at 15:31