Reputation: 155
I'm trying to pass a query result to an SSH command.
command $queryresult
The query result can be one or more then one row and in case of more than one row, I need to concatenate them.
If I run mysql command with -N and -e parameters,
mysql -u $MUSER -p$MPASS -D $DBS -N -e "$QUERY6"
I obtain one result per row
result1
result2
Is there a way to separate them by a space?
result1 result2
Query is
SELECT view_id
FROM mview_state
WHERE STATUS != 'idle' AND (CURRENT_TIMESTAMP() + 60000 - updated) > 1800
Upvotes: 0
Views: 145
Reputation: 49373
Use GROUP_COCAT
SELECT GROUP_CONCAT(mview_state.view_id SEPARATOR ' ') view_id
FROM mview_state
WHERE `STATUS` != 'idle' AND (CURRENT_TIMESTAMP() + 60000 - mview_state.updated) > 1800
GROUP BY view_id
Sidenote:
STATUS
is a MySQL Keyword and should ideally not be used as a column name. Column names in MySQL should be universally lower case.
Upvotes: 2