嗨,我是开发新手。亲自承担我的编码。我创建了一个带有id(自动增量),状态,票号和代码的表arlog。票证和代码编号设置为唯一。也就是说这个组合的副本不能再次插入。但单独的票号或cpt可以插入多次。它工作正常。现在我想使用与arlog表票号和代码相关的另一个表的select查询。这是select语句
$result = mysql_query("SELECT * FROM `ar` C WHERE provider='".$_SESSION['PROVIDER']
."' AND C.`TicketNo` IN ( SELECT TicketNo FROM `arlog` L where L.status NOT IN('New','Completed','Completed(Ar_aging)
','Completed(Rework)','Rework','Completed_Followup','Completed_Supervising' )
and L.assign='".$_SESSION['NAME']."' ) order by id desc") or die(mysql_error());
查询检查arlog中的票号并正确显示。但我想在arlog中结合TicketNo和Code。我做了研究但找不到解决方案。首先是可能吗?
答案 0 :(得分:0)
请尝试以下sql:
SELECT L.TicketNo ,L.Code,C.* FROM `ar` C left join `arlog` L ON C.TicketNo = L.TicketNo where C.provider='your condition' and L.status NOT IN('New','Completed','Completed(Ar_aging)','Completed(Rework)','Rework','Completed_Followup','Completed_Supervising' ) and L.assign='your condition' order by by C.id desc
希望这可以帮到你!
答案 1 :(得分:0)