Skip to content
Advertisement

Combining sql queries together

I am trying to simplify my current query code. Is there a simpler way of combining both queries into one?

Here is what I have tried so far. Although it seems really messy and clunky. This query requests all the clients

I then have another request inside to find if the client has a booking

Done represents if the job is completed, and there can only be 1 uncompleted job per client at a time.

Explanation:

The code needs to show all the clients and if the client has a booking and if the other database returns a result, the booking button won’t appear, if no results (i.e, all previous bookings for that client are 1) a book button appears.

Advertisement

Answer

I think you want:

This attempts to find a uncompleted row in booking for each client. Column completed in the resultset contains 0 if the client has an uncompleted row, else 1.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement