join - What is wrong with my MySQL query (UNION)? -


i hope can me here. i'm working on pms system , want run simple select statement list of secret codes customers based on of parcels have arrived , transaction type. 'transferconfirmation' table has customer id , secret code , displays 1 row each instance reason, when use following query:

select `tc`.`transferid` `transferid`,        `c`.`firstname` `firstname`,        `c`.`lastname` `lastname`,        `tc`.`secretcode` `secretcode`,        'purchase order' `transactiontype` (((((`db`.`transferconfirmation` `tc`           join `db`.`customer` `c` on((`tc`.`customerid` = `c`.`customerid`)))          join `db`.`transfer` `t` on((`t`.`transferid` = `tc`.`transferid`)))         join `db`.`transferentry` `te` on((`t`.`transferid` = `te`.`transferid`)))        join `db`.`purchaseorder` `po` on((`te`.`referenceid` = `po`.`purchaseorderid`)))       join `db`.`purchaseorderentry` `poe` on(((`po`.`purchaseorderid` = `poe`.`purchaseorderid`)                                                , (`te`.`referenceentryid` = `poe`.`purchaseorderentryid`)))) (`poe`.`collectionstatus` = 0) union select `tc`.`transferid` `transferid`,        `c`.`firstname` `firstname`,        `c`.`lastname` `lastname`,        `tc`.`secretcode` `secretcode`,        'shipping order' `transactiontype` (((((`db`.`transferconfirmation` `tc`           join `db`.`customer` `c` on((`tc`.`customerid` = `c`.`customerid`)))          join `db`.`transfer` `t` on((`t`.`transferid` = `tc`.`transferid`)))         join `db`.`transferentry` `te` on((`t`.`transferid` = `te`.`transferid`)))        join `db`.`shippingorder` `so` on((`te`.`referenceid` = `so`.`shippingorderid`)))       join `db`.`shippingorderentry` `soe` on(((`so`.`shippingorderid` = `soe`.`shippingorderid`)                                                , (`te`.`referenceentryid` = `soe`.`shippingorderentryid`)))) (`soe`.`collectionstatus` = 0) 

i keep getting results duplicate data difference transaction. guess question is, if secret code has been selected once, how prevent other row displaying same code.

use union operator. union operator remove duplicate records each query (union all retain them).

select transferid, firstname, lastname, secretcode,     'purchase order' transactiontype ... union select transferid, firstname, lastname, secretcode,     'purchase order' transactiontype ... 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -