Is it possible to query data like this from SQL?

Solution 1:

You could do it with javascript but could get messy. Something like this(untested):

const newArray = [];
data.forEach((item) => {
  const exists = newArray.find(
    (el) =>
      el.user === item.user &&
      el.work === item.work &&
      el.first_name === item.first_name
  );

  if (exists) {
    exists.city.push(item.city);
  } else newArray.push({ ...item, city: [item.city] });
});