简体   繁体   中英

using subselect in mysqli

I have a query which works currently, but we added more the possibility of one customer doing more than one test drive. this additional test Drive is on a different table. The customer ID is an auto increment number on the testdriveform table. So I need to check for addition entries, based on the customer id from table 1 in table 2 and list them along withe the rest.

SELECT * FROM testdriveform Where SalesAgent not like '%Test%' and SalesAgent like '%$Sales%' and Date between '$sDate' and '$eDate' and Stock != '' order by Date, SalesAgent;

I need to add a subselect I think. Something that adds

SELECT * FROM testdrives WHERE custID = testdriveform.id 

phpmyadmin is down on bluehost..again. Anyone?

NO, you don't need a subselect; rather need a JOIN between the tables like

SELECT td.*, tdf.*
FROM testdriveform tdf 
JOIN testdrives td ON td.custID = tdf.id 
Where tdf.SalesAgent not like '%Test%' 
and tdf.SalesAgent like '%$Sales%' 
and tdf.`Date` between '$sDate' and '$eDate' 
and tdf.Stock != '' 
order by tdf.`Date`, tdf.SalesAgent;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM