0

my SQL Query:

select * from tbl_vehicle 
join tbl_driver on tbl_vehicle.pk_vehicle_id = tbl_driver.fk_vehicle_id 
join tbl_location on tbl_driver.pk_driver_id = tbl_location.fk_driver_id 
join tbl_company on tbl_driver.fk_company_id= tbl_company.pk_company_id 
where driver_mob 
NOT IN 
(
select * from tbl_vehicle 
join tbl_driver on tbl_vehicle.pk_vehicle_id = tbl_driver.fk_vehicle_id 
join tbl_location on tbl_driver.pk_driver_id = tbl_location.fk_driver_id 
join tbl_company on tbl_driver.fk_company_id= tbl_company.pk_company_id 
where 
(tbl_location.latd  BETWEEN '9.835443' AND '10.226975' )
 AND 
(tbl_location.longd  BETWEEN '76.201205' AND '76.77894') 
and 
tbl_company.Company_name='Kerala' 
and 
tbl_driver.active_flag=1
);

it is showing error 1241, how can i modify this to avoid error? any piece of code is appreciated and thanks in advance.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
jasim
  • 459
  • 1
  • 6
  • 24
  • 2
    `where driver_mob NOT IN ( select driver_mob from tbl_vehicle ....` Or better yet use a correlated subquery. – Mihai Oct 11 '14 at 17:00
  • @Mihai, how to use correlated subquery? – jasim Oct 11 '14 at 17:03
  • `..WHERE NOT EXISTS(SELECT 1 FROM all that JOIN fest WHERE .. AND someAlias.fk_vehicle_id =tbl_driver.fk_vehicle_id)` Just put an alias on the same table name with the table name in the outer query. – Mihai Oct 11 '14 at 17:09
  • 1
    am a beginner in programming, not familiar with join function. first method worked for me. thanks :) – jasim Oct 11 '14 at 17:27

0 Answers0