You are using INNER JOIN so select will only return the results if the conditions shown are true.
You said the records have the following values:
Table teams:
id = 1, name = Barcelona and photo = upada normally
id = 2, name = Real Madrid and photo = upada normally
Table posts:
id_time_1 = 1
id_time_2 = 2
Your select:
SELECT * FROM equipes
INNER JOIN posts
ON equipes
.id
= posts
.id_time_1
AND equipes
.id
= posts
.id_time_2
Realize that there is a logic error, because the value of id_time_1 = 1
and id_time_2 = 2
. Then when compared to the id 1 of the teams table the first condition will be true and the second false (resulting in false and will not bring anything). When compared to the id 2 of the teams table the first condition will be false (then neither fall in the second and bring nothing too).
There are several ways to fix this, but for simplicity and ease I would add an id_teams field in the post table and associate this field in select. Example:
SELECT * FROM equipes e
INNER JOIN posts p ON p.id_equipes = e.id
what is the purpose of
id_time_1
andid_time_2
? This looks like you need a new table ...– rray
Ex: the team table has two record. id = 1, name = Barcelona and photo = upada normally. and the other record. id = 2, name = Real Madrid and photo = upada normally. And the posts table has a record. id = 1, title = Post test, id_time_1 = 1, id_time_2 = 2. how would I have q fzr this query
– ihudsonbr
I think I got it, I could put the select you tried on the question?
– rray
here the select I tried. SELECT * FROM
equipes
INNER JOINposts
ONequipes
.id
=posts
.id_time_1
ANDequipes
.id
=posts
.id_time_2
– ihudsonbr
Would you just do a query not be better? Once you have the post data, just do a select for each id_time. I find it cleaner for maintenance than the joins down here.
– Daniel