Reputation: 199
i try to retrieve datas from my database with following sql.
select mc.ADD_DATE,mc.MOVIE_ID,mc.COMMENT,m.ID,m.NAME
from MOVIE_COMMENT as mc
INNER Join MOVIE as m ON m.ID=mc.MOVIE_ID
WHERE user_ID = " . $getUser->id . "
and STAT='onayli'
ORDER BY mc.ADD_DATE DESC LIMIT " . $commentCount . "
I use Inner join because i also retrieve movie names from another table.
mc = MOVIE_COMMENT table
m = MOVIE Table
My problem is that when i try to retrieve mc ids, it gives me the movie ids why?
Upvotes: 0
Views: 81
Reputation: 2639
You're returning the ids from the MOVIE_COMMENT table as mc.MOVIE_ID. Thus, when you try to access there (e.g., from PHP), you need to access MOVIE_ID. Asking for ID will return m.ID, the ids from the MOVIE table.
Upvotes: 0
Reputation: 1275
If you want the Movie_Comment IDs, you need to return the mc.ID field.
SELECT mc.ID as Movie_Comment_ID, mc.ADD_DATE, mc.MOVIE_ID, mc.COMMENT, m.ID, m.NAME
FROM MOVIE_COMMENT as mc
INNER Join
MOVIE as m
ON m.ID = mc.MOVIE_ID
Upvotes: 3