I have values array as :
const params = [
['2022-12-10', 'aaaaa', '2022-12-01', 'xhxha', '2022-12-10'],
['2022-12-11', 'ababa', '2022-12-01', 'xhxha', '2022-12-11'],
['2022-12-12', 'acaca', '2022-12-01', 'xhxha', '2022-12-12'],
['2022-12-13', 'adada', '2022-12-01', 'xhxha', '2022-12-13'],
];
const data = await db.query(`select id, title, DATE_FORMAT(end_date,"%Y-%m-%d") as end_date ABS(DATEDIFF(?, end_date))+1 as delay from chart
where uid = ?
and date = ?
and project_uid = ?
and end_date = ?
and completed is true;
`, [params]);
I want to run this query, but all the values are being added to the 1st ? (question mark). I want to have the the values to different ? and get the result.
Also I do not want to run query inside for loop. How do I get the result here?
2
Answers
You can join to a parameters subquery. Since 8.0 you can use VALUES table constructor. Alternatively use SELECT .. UNION ALL in
params
subquery