Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Advice needed on Sql Select
Message
 
 
À
25/04/2014 15:35:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01599095
Message ID:
01599098
Vues:
75
>>>Here's my situation. I'd like to get info from different tables so I'll be using a join.
>>>
>>>as an example let's say I have an employee table. In that table there is the id of the employee, when the employee starts his day defined as an integer and when the employee finished his day defined once again as an integer.
>>>
>>>Now let's say we have a table containing a bunch of times.
>>>
>>>structure of the time table could be an integer for the primary key and a string for the time possible and this would be 5 characters.
>>>
>>>
>>>Table employee
>>>
>>>EmployeeId AutoInt
>>>BeginTime Integer
>>>EndTime Integer
>>>
>>>
>>>Table TimeDef
>>>IdTime Integer
>>>DescTime C5
>>>
>>>a select for this could be :
>>>
>>>select EmployeeId, DescTime ;
>>>from Employee ;
>>>left join TimeDef on employee.BeginTime = TimeDef.IdTime
>>>
>>>This previous select should work ok. But how do I get the description (DescTime) for my EndTime in the same select?
>>
>>You need to join with your timedef table twice under different alias, e.g.
>>
>>select EmployeeId, t1.DescTime  as StartTime, t2.DescTime as EndTime;
>>from Employee ;
>>left join TimeDef t1 on employee.BeginTime = t1.IdTime -- why left JOIN?
>>LEFT JOIN TimeDef t2 on Employee.EndTime = t2.IdTime
>>
>>Also, why you're using LEFT JOIN instead of the INNER JOIN?
>
>Thanks you Naomi. Why should I use inner instead of Left?

Because most likely there is a relationship (it should be) between these two tables, so you should not have times not defined in the TimeDef table. And that's being the case, it should be an inner join.
Unless, of course, some times are NULL in the Employee table. In this case LEFT JOIN is correct.

BTW, some database experts prefer to use plural for table names.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform