How to bring data from another table related to a userid (JOIN ???)

0

I have the following tables: Users

Andinvestments

Theinvestmenttablehastheuserid.I'malreadygettingregistered.HowdoIshowonauser'sscreentheinvestmentsmadebyhim?I'malreadyabletoregisterandhavetheuseridrecordedrightaway.Myscreenwillbethisbelow,Iwillonlyshowthedateandvalueoftheinvestmenttable:

    
asked by anonymous 12.10.2018 / 06:18

1 answer

0

I think the following query sql will solve your problem:

SELECT i.created_date, i.valor 
FROM Usuario AS u JOIN Investimento AS i ON u.id = i.id_usuario 
ORDER BY i.created_date;

As you can see in this query, I added ORDER BY only to better organize the query return.

If you want to specify the user id that will be returned the query would be as follows:

SELECT i.created_date, i.valor 
FROM Usuario AS u JOIN Investimento AS i ON u.id = i.id_usuario 
WHERE u.id = ?????
ORDER BY i.created_date;

Where "?????" is your attribute.

    
12.10.2018 / 06:52