mateuszjarosz mateuszjarosz - 4 months ago 7
MySQL Question

Get name from another table using an ID

I've got two tables, one is called

matches
and the other one is called
teams
.
matches
only list team IDs, but I want my query to include team names from
teams
. I tried different solutions already and I came up with this query, but it didn't work:

SELECT * FROM `matches` WHERE `mWeek` = 1
INNER JOIN `teams`.`tName` ON `matches`.`tHome` = `teams`.`tId`


That query returned error #1064. I'm happy to provide more details if necessary.

Answer

Query will be like these

SELECT
    `matches`.*, 
    `teams`.`tName`
FROM
    `matches`
INNER JOIN `teams` ON `matches`.`teamId` = `teams`.`tId`
WHERE
    `mWeek` = 1