Val
Val

Reputation: 17542

mysql dynamic table standard

$query = 'SELECT * FROM tbl as t WHERE t.id = 1';

in the above statement would it be wrong to do the following?

`t`.`id`

if yes then whats the correct way by the mysql standards ?

Upvotes: 1

Views: 198

Answers (1)

Adam Lukaszczyk
Adam Lukaszczyk

Reputation: 4926

ist good in both cases:

$query = 'SELECT * FROM tbl as t WHERE t.id = 1';

$query = 'SELECT * FROM tbl as t WHERE `t`.`id` = 1';

the apostrophes are good because the column name could be the same as mysql function name like FROM so in that case to prevent error you put the column name into apostrophes

Upvotes: 2

Related Questions