M
M
MdaUZH2017-01-29 16:04:06
MySQL
MdaUZH, 2017-01-29 16:04:06

SQL JOIN query, how right?

Hello everyone, there are 2 tables:
users:
id | name | surname
courses:
id | user_id | description | type
How will it be correct to get all courses with type = 1 + by user_id to get name and surname?
I have been working with SQL JOIN's for a long time, I don’t even know how to do it ..
something like this?:

SELECT c.*, u.name, u.surname FROM courses AS c INNER JOIN users AS u ON c.type = 1 AND u.id = c.user_id

??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jasonOk, 2017-01-29
@MdaUZH

SELECT c.*, u.name, u.surname FROM courses c 
LEFT JOIN users u ON u.id = c.user_id WHERE c.type = 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question