Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a problem with the current request that doesn't return what i hope
SQL
SELECT * FROM Training where _ID NOT IN( select Training_idTraining from Training) and _ID IN(select _ID from TrainingManager where idManager=3)

the request aims to retrieve all the training created by manager with id = 3(this condition explained by second condition after the "where") and that are not assigned to other canceledtraining (explained by the first condition "after the where the table training contains the column "Training_idTraining" which is null if the training is not canceled and filled with the id the future training which will replace the current training if the later was canceled.
when i erase the second condition i get all trainings created by the manager but when i add the first condition to get all the one that aren't assigned to any previous canceled training i don't any record.
Posted
Updated 12-Jun-12 6:43am
v2

Your requirements are not very clear. But this should be it if it is what I read from your question:

SQL
SELECT
    *
FROM
    Training AS T INNER JOIN TrainingManager AS TM ON
        T._ID = TM._ID
        AND TM.idManager = 3
WHERE
    T.Training_idTraining <> NULL -- this is NULL if the training is cancelled
 
Share this answer
 
v3
Comments
Maciej Los 12-Jun-12 12:58pm    
Manas, i see a liitle error: INNER JOIN AS TrainingManager TM It should be INNER JOIN TrainingManager AS TM. Besides of that, it's OK. +5!
I have similar solution ;)
Manas Bhardwaj 12-Jun-12 13:19pm    
Thx :)
Maciej Los 12-Jun-12 13:23pm    
You're welcome ;)
Tim Corey 13-Jun-12 22:09pm    
Great job.
VJ Reddy 14-Jun-12 13:26pm    
Good answer. 5!
Try this:
SQL
SELECT T.*, TM.*
FROM  Training AS T LEFT JOIN TrainingManager AS TM ON T._ID = TM._ID
WHERE NOT T.Training_idTraining IS NULL AND TM.idManager = 3
 
Share this answer
 
Comments
Manas Bhardwaj 12-Jun-12 13:18pm    
Correct +5
Tim Corey 13-Jun-12 22:09pm    
Nice job. +5
VJ Reddy 14-Jun-12 13:27pm    
Good answer. 5!
this is the code sql that solve my request:
<pre lang="SQL">SELECT * FROM Training where _ID NOT IN( select Training_idTraining from Training where Training_idTraining is not null) and _ID IN(select _ID from TrainingManager where idManager=3) and Training_idTraining is null
 
Share this answer
 
Comments
Tim Corey 13-Jun-12 22:11pm    
Couple things. First, you are doing expensive queries (IN and NOT IN) when you have been provided with two working solutions that are less expensive. Second, if you have a working solution, please mark one or more of the solutions as the answer so that future readers know this question is closed. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900