L
L
leni_m2018-02-16 14:56:27
MySQL
leni_m, 2018-02-16 14:56:27

Can you help with JOIN?

It is necessary to make selection from two tables on identical id.
Wrote the query "SELECT * FROM table1 INNER JOIN table2 using(id) WHERE id=1";
And he chooses everything well, but:

  1. I also need to sort by the date field. The thing is that it turns out 2 columns with the same name "date" and adding "ORDER BY date DESC" causes the error "#1052 - The 'date' column in the order clause is ambiguous". And how can these two columns be combined into one?
  2. There are also columns with the same names, for example "name". So tell me how to make it "name1" from the first table, and "name2" from the second?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-02-16
@leni_m

1. Use prefixes, `table1`.`date` and `table2`.`date`
2. Use aliases `table1`.`name` AS `name1`, `table2`.`name` AS `name2`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question