0

create table mainTable as select curr_Table.empID as empID, (currTable.ToTalDays-oldTable.ToTalDays) as DiffDays from currTable left outer join oldTable on currTable.empID = oldTable.empID

This is the query that i use to find the days worked by an employee.

The Problem raises when there is "New Joinee". "oldTable.ToTalDays" will not have any value as no record will be found for "New Joinee" in oldTable. So, for this record DiffDays (Integer-null) results is Zero instead of current total days.

Any way to resolve this problem?

1
  • Never matters as i am interested in learning and doing homeworks through out my life :) Commented Oct 13, 2009 at 7:29

2 Answers 2

1

Not perfectly sure about this one, but I don't think mysql allows

CREATE TABLE AS SELECT ...

sort of things. Doublecheck the manual on that one. Have seen such queries on postgres, but don't remember such ones on mysql...

EDIT:

Performed the double check too and have to admit that CREATE TABLE AS SELECT ... works in deed. Nevermind, gonna get some coffee...

Sign up to request clarification or add additional context in comments.

1 Comment

i found this "CREATE TABLE new_tbl SELECT * FROM orig_tbl" in the above link and still i found "CREATE TABLE AS SELECT ..." works fine!
0
create table mainTable as
select curr_Table.empID as empID,
       (currTable.ToTalDays - ifnull(oldTable.ToTalDays, 0)) as DiffDays 
  from currTable
         left outer join
       oldTable  on currTable.empID = oldTable.empID

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.