-1
SELECT
bookingReference,
SUM(amount)
FROM
rates_Booking
WHERE date BETWEEN '2016-09-01' AND '2016-09-30'
GROUP BY bookingReference;

SELECT booking_type.`name` as booking_type 
FROM booking_type
LEFT JOIN booking ON booking_type.`name`=booking.booking_type;

i want to join both table. i want result like this:

column1            column2   column3
----------
bookingReference    sum(amount)   booking_type
----------
0993979-00          £500     booking
----------
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
P.Sam
  • 1
  • 1
  • there are relation between the 3 tables? if yes on which column .. if not how the value from the two query are related ? – ScaisEdge Oct 04 '16 at 20:37
  • There's not enough information here to answer the question. Given only the columns shown, there doesn't appear to be any common columns that form a relationship between `rates_Booking` and `booking_type`. – spencer7593 Oct 04 '16 at 20:52
  • See http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query – Strawberry Oct 04 '16 at 21:19
  • @scaisEdge- only rate_bookings and booking table has common column name "amount". – P.Sam Oct 05 '16 at 07:58
  • @spencer7593- no common column between rates_booking and booking_type. – P.Sam Oct 05 '16 at 08:01
  • Thank you to all for the help. – P.Sam Oct 05 '16 at 16:03

1 Answers1

0

I am assuming that there is some joining column between the first and second dataset. All I did in this case was join the both on a booking reference column (assuming this column is in both datasets). Really hard to determine with the amount of information given. But if there is a reference column then it would be a simple inner join

SELECT
A.bookingReference,SUM(A.amount), booking_type.`name` as booking_type 
FROM
rates_Booking A
inner join booking_type B ON A.bookingReference = B.bookingReference
left join booking  ON booking_type.`name`=booking.booking_type
WHERE date BETWEEN '2016-09-01' AND '2016-09-30'
GROUP BY A.bookingReference,booking_type.`name`;
Prob1em
  • 74
  • 6
  • This same query give me the error - [Err] 1054 - Unknown column 'booking_type.name' in 'field list' – P.Sam Oct 05 '16 at 08:02
  • sub query is possible with left join and 2 different select queries. – P.Sam Oct 05 '16 at 08:23
  • I was just guessing column names because there is not enough information within your question to give a correct answer – Prob1em Oct 05 '16 at 15:25