How do I set the @DATE
variable by using a table/column reference?
Right now I've set it manually as you can see below with the opening:
SET @DATE = '2012-03-31 01:00:00';
The table from which I would pull the date variable is not the table from which the SELECT statement is pulling.
SQL query mockup:
SET @DATE = '2012-03-31 01:00:00';
SELECT
Column 1
FROM
Table
WHERE
table.column = @DATE
Best Answer
If I understand your question correctly, there are two ways that I can think of:
or
These two are functionally equivalent when only one value is involved, but the second form can also be expanded to handle multiple values.
But your question involved using the resulting @date in your query.
If that's the intended purpose, you can eliminate the variable entirely and use the first example, above, as a subquery inside the final query.
http://dev.mysql.com/doc/refman/5.5/en/comparisons-using-subqueries.html