I would like to obtain a sub-query's return row count in the query itself. Then I will use it in the main query in an if case. I have added an example and, as a dummy string I put QUERY_ROW_COUNT.Is there any function to achieve this? Thanks in advance...Regards...
SELECT period_id,
lt_id,
period_name,
min_stay,
IF(QUERY_ROW_COUNT=1, 1,0) as tag
FROM (SELECT period_id,
lt_id,
period_name,
min_stay,
fromDate,
toDate,
DATEDIFF( '2010-12-27', '2010-12-10' ) as totalDays,
nightly_rate,
case when ('2010-12-10' > fromDate AND '2010-12-27' < toDate) then
DATEDIFF( '2010-12-27', '2010-12-10' )
else 0
end as d6,
case when ('2010-12-10' > fromDate AND '2010-12-27' > toDate) then
DATEDIFF( toDate, '2010-12-10' )+1
else 0
end as d7,
case when ('2010-12-10' < fromDate AND '2010-12-27' < toDate) then
DATEDIFF( '2010-12-27', fromDate )
else 0
end as d8,
case when ('2010-12-10' < fromDate AND '2010-12-27' > toDate) then
DATEDIFF( toDate, fromDate )
else 0
end as d9
FROM `lt_hperiods`
WHERE ('2010-12-10' BETWEEN Date( fromDate ) AND Date( toDate ) )
OR ( '2010-12-27' BETWEEN Date( fromDate ) AND Date( toDate ))
OR ('2010-12-10' <= fromDate AND '2010-12-27' >= toDate )
AND (lt_id=1)) MQS