Cannot reach id from table when using SELECT JOIN
Hello, I have a problem to select the id from the filmer-table when I use JOIN in the SQL-string below. At the moment I only reach the id from the regissorer-table, but I want to reach both id:s from both tables. The thing is that I want to point to a specific movie using its id from the filmer-table in a link, but I also need to be able to point to the regissorer_id to be able to print out names of directors in text.
So, does someone know if this could be fixed in the same SQL-string, like adding some SQL-code to it so I can select both id:s? Would be thankful if someone could help me with this.
$sql = "SELECT * FROM filmer JOIN regissorer ON regissorer.id = filmer.regissor_id";
You cannot use the SELECT * (select all) with a JOIN. you can however do a "selective" select all.
Replace r.col1, ..., r.colN with the columns you want from regissorer.
SELECT f.*, r.col1, ..., r.colN
FROM filmer 'f'
JOIN regissorer 'r'
ON r.id = f.regissor_id
The filmer 'f' (or filmer AS 'f') is an alias (simply there for illustration, but comes in handy on very long statements).
That solved the problem, thank you very much! :-D
Originally Posted by ShrineDesigns
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)