A
A
Albert Kazan2018-02-21 16:58:08
MySQL
Albert Kazan, 2018-02-21 16:58:08

How to build a SELECT query combined from two tables?

The first table is something like news
columns id | owner_id | subject
Second table users
id | Nick | photo_res
Through a cycle I sort through it and I deduce in html. It is necessary that the user himself is also selected in the search, that is, owner_id is the id from the second table. You can't make a separate request.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2018-02-21
@Farrien

use join
like this:

SELECT * FROM table1
LEFT JOIN table2 ON table1.owner_id = table2.id

A
Albert Kazan, 2018-02-21
@Farrien

SELECT t1.poster_id, t1.subject, t1.time, t2.id, t2.name, t2.second_name FROM adverts AS t1, people AS t2 WHERE t1.poster_id=t2.id GROUP BY t1.poster_id

Hooked up, but it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question