Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Mayur Pande
PLUS
Mayur Pande
Courses Plus Student 11,711 Points

[SOLVED] Selecting data from sql queries

I have a mysql query that selects the capacity of something and it also runs a check to see the availability. This works fine however I want to also select the count of the different table.

Here is the query that works;

select driver.capacity, (capacity - (select count(*) from studentdriverdetails where starttime='$starttime')) as available
from driver
where starttime='$starttime'

However I also want to be able to get the result for

select count(*) from studentdriverdetails where starttime='$starttime'

within the same query. Is this possible? I tried doing a few left outer joins, but this didn't work.

Mayur Pande
Mayur Pande
Courses Plus Student 11,711 Points

solved it! the answer was in my question. The second query gets updated when data is inserted into the table

1 Answer

Steven Parker
Steven Parker
231,261 Points

Congrats on solving your issue. :+1: Remember to mark your title with [SOLVED] as an alternative to selecting a "best answer" to let folks know the issue is closed.