Skip to content
Advertisement

How can I use a SQL query result as a column in another query?

I got a view that returns weekday. The result will be a column in WHERE clause, something like this:

For example:

Today is sunday, in dvtv_weekday returns SUN In dvtv_delivery exist the column SUN

Is it possible in Mysql? When I run nothing appears

Using I use down below, works

Any answer would really be helpful! Sorry my bad English

Advertisement

Answer

This query:

returns a string like 'SUN' and not the name of the column SUN.
So WHERE is equivalent to:

which will always return no rows.
You need something like this:

I assume that the table dvtv_delivery has all these columns: SUN, MON, ....

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement