mysql - sql statement for two different columns -
i trying make sql query between 2 columns.
table_1
id productname productdescription 1 prod_1 description_1 2 prod_2 description_1 3 prod_3 description_1 4 prod_4 description_1 5 prod_5 description_1 table_2
id product partner 1 1 21 2 2 21 3 3 21 4 1 32 5 1 32 6 4 21 7 5 21 8 5 32 by using query below result list of products selected in table_2. need that, want print values table_1 in same query later programming need that. not sure possible make 1 column print 1 if product_id , id match , if not print 0
$query = "select a.id, a.productname, b.id, b.product, b.partner table_1 left join table_2 b on a.id = b.product b.partner = 21" i want print values table_1 match table_2 selected in table_2. getting stuck here advice appreciated.
as right requirenments untested query should work:
$query = "select a.id, a.productname, b.id, b.product, b.partnerm, case when b.id null 0 else 1 end table_1 left join table_2 b on a.id = b.id , b.partner = 21"
Comments
Post a Comment