How can I do this:
SELECT Board_id FROM topic WHERE Value1='".$value2."' UNION SELECT Name FROM Boards WHERE Id=Board_id
Should I use UNION? Or should I use two different queries? What is better?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a join:
See a SQL join tutorial on W3 Schools: http://www.w3schools.com/sql/sql_join.asp
Note, if you’re using PHP, your code is at risk of SQL injection: http://en.wikipedia.org/wiki/SQL_injection
There are a number of ways to protect against this:
Better yet might be to use a parameterized query, but this depends on whether you’re using PHP’s MySQL or MySQLi libraries.