There is such a task. Pull out the table with a specific sort.

1) By creation date - (there is a date_create field on it I do)

 ORDER BY date_create DESC 

2) Whether actual announcements are - (there is a field archive , where 0 is actual 1 is not)

3) The dispatch date is not later than today - (there is a discharge_date field that stores the dispatch date)

So, how to get everything in one request, first records 1) Fresh by the date of the announcement, Current ads ( archive=0 ), Date sent overdue, ( NOW()<discharge_date )

Made only on the first point, but it's easy.

 SELECT * ,DATE_FORMAT(shipping_date,'%d.%m.%Y') as shipping_date, DATE_FORMAT(discharge_date,'%d.%m.%Y') as discharge_date1 FROM bid_country WHERE id>=0 $string ORDER BY date_create DESC $limit; 

The variables $string and $limit generated before this. You can ignore them, the main thing is how to sort.

  • one
    It is not entirely clear what you want to get into the result. There is some confusion - you are talking about the conditions of the sample, but at the same time you want to shove them into sorting. In principle, this is possible - but for a better understanding of the problem it would be good if you give a simplified example of the data that you have and what you want to get as a result. You can do this for example on sqlfiddle.com - newman
  • You'd better use the request and union stackoverflow.com/questions/19350199/… - AB

1 answer 1

  SELECT * ,DATE_FORMAT(shipping_date,'%d.%m.%Y') as shipping_date, DATE_FORMAT(discharge_date,'%d.%m.%Y') as discharge_date1 FROM bid_country WHERE id>=0 AND discharge_date >= CURDATE() ORDER BY date_create DESC, archive ASC