sql - What is the correct Select Statement for this? -
//this table 1
transactionnum type 65658 0 65659 0 65660 449 65661 0 //this table 2
type description 445 discount #1 446 discount #2 447 discount #3 448 discount #4 449 discount #5 450 discount #6 //this script
select a.transactionnum,b.description table1 a,table2 b a.type=b.type order transactionnum //result
transactionnum description 65659 discount #4 //i want result this, transactionnum 0 type should included in result, please me this, im using sql2000 here.
transactionnum description 65658 0 65659 0 65660 discount #5 65661 0
use left join instead,
select a.transactionnum, coalesce(b.description, cast (a.type varchar(20))) description table1 left join table2 b on a.type=b.type order a.transactionnum to further gain more knowledge joins, kindly visit link below:
output
╔════════════════╦═════════════╗ ║ transactionnum ║ description ║ ╠════════════════╬═════════════╣ ║ 65658 ║ 0 ║ ║ 65659 ║ 0 ║ ║ 65660 ║ discount #5 ║ ║ 65661 ║ 0 ║ ╚════════════════╩═════════════╝
Comments
Post a Comment