Left Join Issues In PHP

I’m just wondering is someone can help me with the following sql error when running php code.

I get the following error:

1054 - Unknown column ‘inn_rooms_36933753.name’ in ‘field list’

The error is despite the fact the column exists in the table.

The code is posted below.

 $sqlDescription = $this->db->prepare('SELECT `inn_rooms_36933753.name`, `inn_rooms_36933753.description` 
											 FROM `inn_rooms_36933753`
											 LEFT JOIN `inn_rooms_rented_36933753` ON `inn_rooms_36933753.name` = `inn_rooms_rented_36933753.roomType` 
											WHERE `inn_rooms_rented_36933753.token` = ?');
	$sqlDescription->execute(array($characterObj->return_room_token()));
									
	$description = $sqlDescription->fetch();

Double check your field names in the table inn_rooms_36933753 - is there really a column called "name’?

Get rid of ` marks in your query.

That did it :). Thanks. Why no ticks on left joins?

Ticks has absolutely nothing to do with left joins. You just have to learn how to use them.

It is not so much the character, but how you used them.

`inn_rooms_36933753.name`, 
`inn_rooms_36933753.description` 

the (correct, but unnecessary) syntax would be

`inn_rooms_36933753`.`name`, 
`inn_rooms_36933753`.`description` 

Though, AFAIK, using backticks is a poor habit to get into using as they can cause problems.

Much better to use non reserved keyword naming and not worry about such things

This is a bit off topic but using aliases can help you get rid of that numerical suffix and perhaps make things a bit easier to maintain. Something like:

    $sql = <<<EOD
SELECT inn_rooms.name, inn_rooms.description 
FROM   inn_rooms_36933753 AS inn_rooms
LEFT JOIN inn_rooms_rented_36933753 AS inn_rooms_rented ON inn_rooms.name = inn_rooms_rented.roomType
WHERE inn_rooms_rented.token = ?
EOD;

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.