V
V
Valera Udav2017-04-11 15:13:17
SQL
Valera Udav, 2017-04-11 15:13:17

How to make a third table using the same column from two tables in SQL?

We have two tables:

title   | deposit
----------------
Title 1 | 0.1
Title 2 | 0.2

post_id | title
-----------
1  | Title 1
2  | Title 2

From these two tables, you need to get the third one:
post_id | title   | deposit
----------------------
1  | Title 1 | 0.1
2  | Title 2 | 0.2

If possible, I would like to do without PHP.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2017-04-11
@TARAKANhoy

SELECT
    table2.post_id as post id,
    table2.title as title,
    table1.deposit as deposit
FROM table2
    LEFT JOIN table1
        ON table2.title = table1.title//джойн по тайтлу; в зависимости от вида хранящихся строк возможно стоит делать приведение к нижнему регистру, удаление пробелов и т.д.

PS It would be better if the join was performed on indexed numeric fields (for the sake of performance).

R
Rsa97, 2017-04-11
@Rsa97

JOIN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question