-1

In the database I have three tables with different number of columns, I need to fetch data in timestamp order. The tables do not have relationships.

Database table:

1

new products will be added to the tables, I need them to be displayed in timestamp order, that is, the most recently added product must be displayed in the first row.

products display must be like:

2

I tried this query, but the output gives me empty values: where is the mistake?

$query = 'SELECT "id", "number", "name", "price", "weight", NULL AS "made", NULL AS "brand" FROM Product 1
 UNION
 SELECT "id", "number", "name", "price", "size", NULL AS "made", NULL AS "brand" FROM Product 2
 UNION
 SELECT "id", "number", "name", "price", "size", "made", "brand" FROM Product 3
 ORDER BY "date" DESC';

How to implement so that the last added product is displayed first in the list of products?

David
  • 53
  • 2
  • 5
  • `ORDER BY \`date\` DESC`? – Nick Jan 30 '21 at 23:15
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](//creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](//meta.stackexchange.com/q/5221) – Sabito stands with Ukraine Jan 31 '21 at 17:35
  • Column names in MySQL should be unquoted, or if escaping *is* required, enclosed in backticks (`\``) – Nick Feb 01 '21 at 00:57

1 Answers1

-1

This query should work:

SELECT number, name, price, null as size, weight, null as made, null as brand FROM Product 1
UNION
SELECT number, name, price, size, null as weight, made, brand FROM Product 3
UNION
SELECT number, name, price, size, null as weight, null as made, null as brand FROM Product 2
ORDER BY date DESC
Mutabor
  • 19
  • 8