php - sql query to merge data of two table and display output -
below 2 table .
i need join both table data , fetch result accordingly...
for ex -
in scheme master table there 8 rows different receipt no.
in receipt entry table there 2 receipt created ...
so need display balance receipt scheme master table book , receipt not present in receipt entry table.
table name - scheme_master
book_no2 receipt_no createddate 401 10 15-03-2015 401 11 15-03-2015 401 12 15-03-2015 401 13 15-03-2015 403 25 15-03-2015 403 26 15-03-2015 403 27 15-03-2015 403 28 15-03-2015 405 35 15-03-2015 405 36 15-03-2015 405 37 15-03-2015 405 38 15-03-2015
table name - receipt_entry
book_no receipt_no 401 10 403 26
i need receipt not present in receipt entry table.
expected output
book no balance receipt createddate 401 11 15-03-2015 401 12 15-03-2015 401 13 15-03-2015 403 25 15-03-2015 403 27 15-03-2015 403 28 15-03-2015
sql:
select distinct sm.receipt_no receipt,sm.book_no2 book,sm.created printeddate,sm.city cityname scheme_master sm left join receipt_entry re on re.receipt_no = sm.receipt_no sm.book_no2 between :book_no , :book2 , re.receipt_no null
first, shouldn't need distinct
, if join correctly on both book_no
, receipt_no
. second, condition in where
clause turning left join
inner join
, because null
values fail comparison. condition should on first table, not second.
so, try this:
select sm.book_no2 book, sm.created printeddate, sm.receipt_no receipt, re.bookingdate bookingdate, re.surveyor_name scheme_master sm left join receipt_entry re on re.book_no = sm.book_no2 , re.receipt_no = sm.receipt_no sm.book_no = 401;
Comments
Post a Comment