Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL How to display data before a certain date

Tags:

date

sql

I have a couple of tables. One is a worker table which displays worker code, firstname and lastname. Job dates which shows worker code, date of job start, end and job area code. Supervisor has worker number, firstname, surname and job area code. Job area has job area code name and supervisor.

What I'm trying to do is display the worker code before date 10/09/10 Since I am new to this, I'm trying to do it all written and theory first before making the database.

Does this sound right? I'm not too sure about the date thing.

select worker
From Job Dates
where job start < '10/09/10'

In theory this sounds right to me, but does it somehow need to tell the query it is a date stamp?

I then want to find the surname of workers and the surnames of their supervisor if the workers started the job before the 10/09/10? I'm guessing this will be with a JOIN?

Thanks

like image 367
user2172295 Avatar asked Mar 17 '13 01:03

user2172295


People also ask

How do I SELECT a specific date range in SQL?

SELECT * FROM PERSONAL WHERE BIRTH_DATE_TIME BETWEEN '2001-03-01 11:00:00' AND '2005-03-01 22:00:00';

How can I get 30 days before a date in SQL?

SELECT (column name) FROM (table name) WHERE (column name) < DATEADD(Day,-30,GETDATE()); Example.


1 Answers

You're on the right track. Not knowing the schema of your database, your ultimate query will look something like this:

select w.surname, s.surname
From worker w INNER JOIN JobDatesTable jdt on w.id = jdt.id
              INNER JOIN SuperVisor s on w.id = s.id
where jdt.jobstart < '20101009'
like image 56
Jack Marchetti Avatar answered Oct 03 '22 17:10

Jack Marchetti