0

I am trying to create flexible search query as below :

SELECT uniontable.PK FROM
(
   {{
      SELECT {p1:PK} AS PK FROM {Product AS p1},{Product AS p2} 
      WHERE {p1.code} = {p2.Att1}
   }}
   UNION ALL
   {{
      SELECT {p:PK} AS PK FROM {Product AS p}
      WHERE {p1.Att1} is not empty
   }}
) uniontable

Can anyone tell mehow to use "ORDER BY " creation time of product keyword in above query?

ASMA2412
  • 61
  • 1
  • 5
  • Why is MySQL tagged here? – Raymond Nijland Jul 01 '19 at 13:21
  • I don't understand your query fully but try this `SELECT uniontable.PK FROM ( {{ SELECT {p1:PK} AS PK, {p1:creationtime} AS creationtime FROM {Product AS p1},{Product AS p2} WHERE {p1.code} = {p2.Att1} }} UNION ALL {{ SELECT {p:PK} AS PK, {p:creationtime} AS creationtime FROM {Product AS p} WHERE {p.Att1} is not empty }} ) as uniontable ORDER BY uniontable.creationtime` – HybrisHelp Jul 02 '19 at 05:39

1 Answers1

0

Try this one, it's more simple :

 SELECT {p1:PK} AS PK FROM {Product AS p1},{Product AS p2} WHERE {p1.code} = {p2.Att1} AND {p1.Att1} is not empty ORDER BY {p1.creationtime}

Hope this helps

Benkerroum Mohamed
  • 1,867
  • 3
  • 13
  • 19