MySQL Need some help with a query

Posted by Jules on Stack Overflow See other posts from Stack Overflow or by Jules
Published on 2011-01-08T14:45:32Z Indexed on 2011/01/08 14:54 UTC
Read the original article Hit count: 257

Filed under:

I'm trying to fix some data by adding a new field.

I have a backup from a few months ago and I have restored this database to my server.

I'm looking at table called pads, its primary key is PadID and the field of importance is called RemoveMeDate. In my restored (older) database there is less records with an actual date set in RemoveMeDate. My control date is 2001-01-01 00:00:00 meaning that the record is not hidden aka visible.

What I need to do is select all the records from the older database / table with the control date and join with those from the newer db /table where the control date is not set.

I hope I've explained that correctly.

I'll try again, with numbers. I have 80,000 visible records in the older table (with control date set) and 30,000 in the newer db/table. I need to select the 50,000 from the old database, to perform an update query.

Heres my query, which I'd can't get to work as I'd like. jules-fix-reasons is the old database, jules is the newer one.

select p.padid 
from `jules-fix-reasons`.`pads` p
JOIN `jules`.`pads` ON p.padid = `jules`.`pads`.`PadID` 
where p.RemoveMeDate <> '2001-01-01 00:00:00' AND 
`jules`.`pads`.RemoveMeDate =     '2001-01-01 00:00:00'

© Stack Overflow or respective owner

Related posts about mysql