0

How can relise in one query this SELECTs from tables without relationship?

SELECT discount_rate.valueSet, discount_rate.dateSet 
FROM discount_rate 
WHERE discount_rate.dateSet<='2011-12-11' 
ORDER BY discount_rate.dateSet DESC LIMIT 1; 

SELECT min_wage.valueMonth AS min_wage_month, min_wage.valueDay AS min_wage_day 
FROM min_wage 
WHERE min_wage.dateSet<='2011-12-11' 
ORDER BY min_wage.dateSet DESC LIMIT 1;

SELECT max_wage.valueWage 
FROM max_wage 
WHERE max_wage.dateSet<='2011-12-11' 
ORDER BY max_wage.dateSet DESC LIMIT 1;
chance
  • 6,307
  • 13
  • 46
  • 70
Alexander Shlenchack
  • 3,779
  • 6
  • 32
  • 46
  • What do you mean when you are saying 'without relationship? Do you know the fields in both tables to connect tables? If you do, you can write SELECT * FROM t1, t2 WHERE t1.f1 = t2.f2 and t1.f3 = t2.f4 – ceth Dec 12 '11 at 11:35
  • I want to get this result table: |valueSet|dateSet|min_wage_month|min_wage_day|valueDay|valueWage| – Alexander Shlenchack Dec 12 '11 at 11:46

1 Answers1

2

Since every one of the 3 queries returns one row, you can wrap them in a query with CROSS JOIN:

SELECT valueSet
     , dateSet
     , valueMonth
     , valueWage 
FROM
    ( SELECT ... ) AS q1        --- subquery 1
  CROSS JOIN
    ( SELECT ... ) AS q2        --- subquery 2
  CROSS JOIN
    ( SELECT ... ) AS q3        --- subquery 3
ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235