0

everyone. I have 2 tables

Lobby:

|lobby_id (pk, a_increment) | t_id | u_id |
-------------------------------------------
|1                          | 6    | 131  |

Trips:

|tid | t_name | t_desc | max_size |
----------------------------------
|6   | GO TO HELL | DSADA | 13  |
|7   | GO TO das  | DSADA | 9   |
|7   | GO TO das  | DSADA | 9   |

I need to count u_id from lobby where t_id = 6 (tid in Trips table) and display: count and max_size from (trips) my sql query so simple:

SELECT count(b.u_id) as counter, a.size as p_size
        from trips a
        left join lobby b ON b.t_id=6

But the query result show me not counter = 1 and max_size = 13, this query returs counter 3 and max_size 13

2 Answers 2

2

You need a predicate matching records from both tables in the ON clause of your query:

SELECT count(b.u_id) as counter, b.max_size 
from trips a
left join lobby b ON a.tid = b.tid 
WHERE a.t_id=6
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thank you so much. You save a lot of my time, cause i'm not good in sql :(
@ATIKON Glad I was able to help. Please mark this, or any other, answer as accepted if it helped you solve your problem.
0

I don't understand why you have a join at all:

SELECT COUNT(*) as counter, MAX(a.size) as p_size
FROM trips t
WHERE t.tid = 6

All the information is in one table.

1 Comment

I need to count u_id from lobby.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.