How to retrieve values from two tables in Mysql

0

It's the first time I ask a question here, and I'm having the following difficulty.

I am doing my info CBT, it is a site for students and such ... is it like Facebook bags? I caught in the part where PHP retrieves the data from the 'post' table of Mysql to appear on the timeline.

I tried this way:

SELECT * FROM 'usuario', 'post' WHERE 'usuario'.'id' = '[ID_DO_USUÁRIO]'

And using PHP's Var_dump () I get this result:

I'mnotsurewhattodo,

ThenItriedlikethis:

(Ishouldhavemissedthisclasskk)

SELECT'id','nome','sobre_nome','foto'FROM'usuario',SELECT*FROM'post'WHERE'usuario'.'id'='9223372036854775807'

Andgivemethiserror:

#1064-YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'SELECT*FROM'post'WHERE'usuario'.'id'='9223372036854775807'LIMIT0,25'atline1

Ifyounoticed,intheresultofVar_dump...Igettworesultsthatisequivalenttotheuserid(unnecessary)

This is personal, I do not know if they will get the logic, but I just want to get some (not all) arguments from the 'user' table and the 'posts' table without having to do 2 querys (I do not know if it's like this that speaks ...).

In short, Relief kk.

    
asked by anonymous 25.09.2017 / 22:28

2 answers

0

You can use JOIN to join the results of the two tables before from you specify all the columns you want as return.

SELECT id, name, about_name, photo FROM post INNER JOIN user ON user.id = post.id_user_post WHERE user.id = 9223372036854775807

Learn more. link

    
25.09.2017 / 22:39
0

If I understand you, you want to relate these two tables.

Then you can use the inner join in the query, for example:

SELECT nome, sobre_nome, foto
FROM usuario
INNER JOIN post ON usuario.id = post.idusuario;

Take a look at it to get a better understanding: link

    
25.09.2017 / 22:38