How to make an INNER JOIN bringing everything from two tables and one more "max" in a specific field?

-1

Good people, to be more specific I have two tables. table 01:

...andtable02:

...andIwouldliketodoa"select" bringing all of these two tables, but where in the "dots" field (table 02) you have the highest number of points, how to do that?

Eg: Alex Bernardes, 20.00, 15.00, 35.00, 01/11/2017 and the points: 110.

    
asked by anonymous 16.11.2017 / 11:50

3 answers

0

For this case you should use sub-query, so you get only the largest of table 2.

SELECT tabela1.*,tabela2.* FROM tabela1 INNER JOIN (SELECT * FROM tabela2 WHERE pontos = (SELECT MAX(pontos) FROM tabela2)) as tabela2 ON tabela1.Id = tabela2.garcom_id ;
    
16.11.2017 / 12:15
1
SELECT tabela1.*, tabela2.pontos, tabela2.garcom_id FROM tabela1 JOIN tabela2 WHERE tabela2.garcom_id = tabela1.id

So you join the 2 tables, returning only the dots and the garcom_id field (it is necessary to make the comparison).

    
16.11.2017 / 11:56
0

Just make a SELECT using the INNER JOIN clause, which works for a join of two or more tables. So, I'll leave below an example of how you should do to join the tables by bringing only the pontos field of table 2

SELECT tabela1.*, tabela2.pontos, FROM tabela1 INNER JOIN tabela2 WHERE tabela1.id = tabela.garcom_id

Remembering that .* is to indicate that it will fetch all records from table 1

    
16.11.2017 / 12:27