SQL Statement help

Capodecina
Permabanned
Joined
31 Dec 2003
Posts
5,172
Location
Barrow-In-Furness
Can't figure out this SQL statement, two tables..

tblCodes
CodeID
CodeCategory

tblHours
TimeCode
blah
blah
blah
blah

Trying to SELECT all fields from tblHours where the CodeCategory = @SelectedCodeCategory

Been messing for a little but I just can't get anything working. Can anyone help?
 
select *
from tblHours, tblCodes
where tblHours.CodeCategory = tblCodes.CodeCategory
and tblCodes.CodeCategory = :value


Or

select * from tblHours
where tblHours.CodeCategory = (select CodeCategory from tblCodes where CodeCategory = :value);

Both the above should work in Oracle
 
SELECT * from tblHours
JOIN tblCodes
ON tblHours.TimeCode = tblCodes.CodeID
WHERE tblCodes.CodeCategory = @SelectedCodeCategory

This is on the assumption that the TimeCode column on the Hours table relates to the CodeID column on the Codes table.
 
Last edited:
SELECT * from tblHours
JOIN tblCodes
ON tblHours.TimeCode = tblCodes.CodeID
WHERE tblCodes.CodeCategory = @SelectedCodeCategory

This is on the assumption that the TimeCode column on the Hours table relates to the CodeID column on the Codes table.

Cheers, yes TimeCode does relate to CodeID :)

How do I limit the fields from tblCodes, I only need CodeCategory really...
 
Back
Top Bottom