O
O
Osklizg2017-08-02 12:24:11
MySQL
Osklizg, 2017-08-02 12:24:11

How to make a selection on 2 tables?

The database has a USERS table with id and name fields, and a USER_LOGINS table with user_id and login_time fields. Write a SQL query that will receive a selection with user_name, login_time fields for USER_LOGINS rows.
How to write a query correctly?
I figured out that I need to use the join operator, but I can’t think through the answer until it turns out like this:
SELECT users.Name AS user_name, user_logins.Login_time AS last_login
FROM users
LEFT OUTER JOIN
user_logins

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Shelemetiev, 2017-08-02
@zoroda

I hope my short tutorial will help you deal with selections as well.

R
RidgeA, 2017-08-02
@RidgeA

in join it is necessary to specify on what field to connect tables.
or so (if the name of the key field in the tables is the same)
select * from table1 join table2 using(id)

S
sasha, 2017-08-02
@madmages

SELECT name, login_time FROM USERS u JOIN USER_LOGINS ul ON u.id=ul.user_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question