Here's my string. I know it's way wrong right now
SELECT binbox_receipt.partner_code
,binbox_receipt.link_id
,binbox_receipt_archive.partner_code
,binbox_receipt_archive.link_id
FROM binbox_receipt, binbox_receipt_archive
where
binbox_receipt_archive.link_id = binbox_receipt.link_id
and binbox_receipt.partner_code = '1154' and binbox_receipt.link_id = '2684'
and (binbox_receipt_archive.partner_code = '1154' and binbox_receipt_archive.link_id = '2684')
I need to check 2 tables if in the first table the link_id and partner_code exist or the second table link_id and partner_code exist
any help would be greatly appreciated I'm a little new at this but having fun trying
Does this work?
SELECT binbox_receipt.partner_code ,binbox_receipt.link_id ,binbox_receipt_archive.partner_code,binbox_receipt_archive.link_idFROM binbox_receiptINNERJOIN binbox_receipt_archiveON binbox_receipt_archive.link_id = binbox_receipt.link_idWHERE binbox_receipt.partner_code ='1154'and binbox_receipt.link_id ='2684'OR (binbox_receipt_archive.partner_code ='1154'and binbox_receipt_archive.link_id ='2684')|||
no errors but no result either. I ran the query for a minute.
individually running the tables for the individual searches it querys quick though
||| SELECT order_id ,binbox_receipt.partner_code
,binbox_receipt.link_id
FROM binbox_receipt
where binbox_receipt.partner_code = '1154' and binbox_receipt.link_id = '2684'
this statement returns 34 records
I need to also check the binbox_receipt_archive for records
|||Try this:
IFEXISTS (SELECT 1FROM binbox_receipt_archive)begin-- here are some records in archive /* do something, for example */SELECT order_id ,binbox_archive.partner_code ,binbox_archive.link_idFROM binbox_archivewhere binbox_archive.partner_code ='1154'and binbox_archive.link_id ='2684'end-- the are some records in archiveelse-- there are no records in archivebegin-- there are no records in atchive /* do something, for example */SELECT order_id ,binbox_receipt.partner_code ,binbox_receipt.link_idFROM binbox_receiptwhere binbox_receipt.partner_code ='1154'and binbox_receipt.link_id ='2684'end-- there are no records in archive
Good luck.
|||I think this is it But not 100% sure
IF EXISTS (SELECT 1 FROM binbox_receipt_archive)or EXISTS (SELECT 1 FROM binbox_receipt)
begin -- here are some records in archive
/* do something, for example */
SELECT order_id ,binbox_receipt.partner_code
,binbox_receipt.link_id
FROM binbox_receipt
where binbox_receipt.partner_code = '1154' and binbox_receipt.link_id = '2684'
end -- the are some records in archive
begin -- there are no records in archive
/* do something, for example */
SELECT order_id ,binbox_receipt_archive.partner_code
,binbox_receipt_archive.link_id
FROM binbox_receipt_archive
where binbox_receipt_archive.partner_code = '1154' and binbox_receipt_archive.link_id = '2684'
end -- there are no records in archive|||
Explain in detail your requirement. Do you care if the values are present in either databace - value1 in table1 and value2 in table2? or do both values have to be in one table in order to select records from it.
|||
it must first search for partner_code and link_id in table 1 and then search for partner_code and link_id in table 2. if its in table 1 display result and or if its in table 2 display results
if something exists in either table I want to see the results
Try the UNION or UNION ALL.
If this doesnt work, please post some sample data from each table and expected output.
SELECT binbox_receipt.partner_code ,binbox_receipt.link_idFROM binbox_receiptWHERE ( binbox_receipt.partner_code ='1154'And binbox_receipt.link_id ='2684')UNION SELECT ,binbox_receipt_archive.partner_code,binbox_receipt_archive.link_idFROM binbox_receipt_archiveWHERE ( binbox_receipt_archive.partner_code ='1154'And binbox_receipt_archive.link_id ='2684')|||
would this work?
begin
SELECT order_id ,binbox_receipt_archive.partner_code
,binbox_receipt_archive.link_id
FROM binbox_receipt_archive
where binbox_receipt_archive.partner_code = '1154' and binbox_receipt_archive.link_id = '2685'
end
begin
SELECT order_id ,binbox_receipt.partner_code
,binbox_receipt.link_id
FROM binbox_receipt
where binbox_receipt.partner_code = '1154' and binbox_receipt.link_id = '2685'
end|||
this works I needed to see if a record existed and this returns one record. I'd say this works for checking for a record the other one works for returning all records.
Thanks.
No comments:
Post a Comment