I am very new to MySQL joins and I have put this together, it is working but I don't know if there is a better way to do this??
$q = $dbc -> prepare("SELECT l.layout, a.email
F开发者_运维知识库ROM layout AS l
JOIN accounts AS a ON (l.id = a.id)
WHERE email = ?");
$q -> execute(array($_POST['email']));
Basically there are 2 tables one called layout and one called accounts, I want to select the layout from layout where the email that matches the id in accounts?
There doesn't appear to be a better way. Yours is fine. The only suggestion is not to use the AS
keyword for table aliases. The AS
in that position is valid in MySQL, but just isn't commonly used. It may not be valid in every RDBMS so it may be best to not to get in the habit of using.
SELECT l.layout, a.email
FROM layout l JOIN accounts a ON (l.id = a.id)
-- ^ ^
-- alias follows table name directly
WHERE email = ?
精彩评论