Records in a table that are not older than two weeks
Hey everyone,
I have a mysql table which has a column DATE which contains the date the enty was inserted
I need to write a script which keeps only those records that are no older than two weeks.
Can this be done in sql?
I can do it in Java but I guess this is not the most efficient way.
I use jsp and servlets in my app.
I just tried out the above code:
DELETE FROM myTableHere WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= DATE;This is the error that I got:
mysql> DELETE FROM myTableHere WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= DATE;
ERROR 1054 (42S22): Unknown column 'DATE' in 'where clause'
mysql>
my sql table has the currentDate column which specifies the current date and time when this entry was inserted into the DB. To get current date and time I use 'now()' function of sql.
what is the problem?
Thanks.
Similar Messages
-
Select multiple row in a table that are not connected
I want to be able to select multiple rows, but want to be able to select rows that are not next to each other. They maybe have one or two rows between. Is there anyway to do this in a table?
ThanksSo do a lot of other people, but you can’t.
Tell Adobe here: https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
Bob -
Messages older than two weeks disappering from inbox? why?
All messages received over two weeks prior are no longer available in my inbox. I scroll down and nothing over two weeks old is available! How do I get Mail to display all my messages?
Thank you, no, I checked that as well... no scheduled deletion, checked on that first thing... this has only happened on my iMac when I upgraded to Yosemite, my MacBook Pro still running 10.9.5 has all my emails (thankfully) from over two years ago! I can't figure this out!
-
Insert Records in one table that's not in other table
Really need your help, I have spent the last five hours on the following code, but can't get it working. What I want done is INSERT records in persons where the same records do not exist in table new_person.
see the below error: rror at Command Line:1 Column:441
Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
INSERT INTO person (last_name, first_name, mi, full_name, id_number, rank, rank_value, temporary, group_number, status, classification, hire_date, unit_code, phone_update, agency, username, agencycourtcode) select last, first_name, mi, full_name, id_number, rank, rank_value, temporary, group_number, status, classification, hire_date, unitcode, phone_update, 'MSP', 'MSP'||id_number, 'MSP' from new_person a where a.status= 'Active' AND where not exists (select last_name, first_name, mi, full_name, id_number, rank, rank_value, group_number, status, classification, hire_date, unit_code, phone_update, agency, username, agencycourtcode from person where a.id_number = person.id_number);Please post your code using tags as this is pretty much unreadable. See instructions here: http://forums.oracle.com/forums/help.jspa
But it looks to me like your INSERT has 16 columns and your SELECT has 17, so you probably have something misaligned.
Also, you have AND WHERE NOT EXISTS, change it to AND NOT EXISTS.
Also, the select list in your NOT EXISTS subquery doesn't need all those columns. Just do a SELECT 1. Oracle doesn't care about the columns only whether a row exists. -
How do you sync Calendar information older than 2 weeks to PALM TX?
Occasionally, I will change information which is older than two weeks in the past on my Oracle Calendar client running on my Windows XP Pro OS. When I sync the data to my Palm TX, it does not get transfered back to my TX calendar. How can I successfully transfer changes (two weeks in the past and beyond) which I make on the PC calendar program to over to my TX so I can read/reference it when I'm away from my desk?
Post relates to: Palm TXThis depends on the program you are using to sync between Oracle and Palm Desktop. See if Palm Desktop is first keep up to date. If not there is a communication break down between Palm Desktop and Oracle. Unfortunately this is something we(Palm Techs) know anything about. There could be others that do on here another would be place to know would be www.treocentral.com.
Post relates to: Treo 800w (Sprint) -
Best approach to delete records that are not in the source table anymore.
I have a situation where I need to remove records from dimensions that are not in the source data anymore. Right now we are not maintaing history, i.e. not using SCD but planning for the next release. If we did that it would be easy to figure the latest records. The load is nightly and records are updated and new added.
The approach that I am considering is to join the dimension tables the the sources on keys and delete what doesn't join. However, is there perhaps some function in OWB that would allow to do this automatically on import so it can be also in place for the future?
Thanks!Bear in mind that deleting dimension records becomes problematic if you have facts attached to them. Just because this record is no longer in the active set doesn't mean that it wasn't used historically, and so have foreign key constraints on it in your database. IF this is the case, a short-term solution would be to add an expiry_date field to the dimension and update the load to set this value when the record disappears rather than to delete it.
And to do that, use the target dimension as a source table, outer join it to the actual source table on the natural key, and so your update will set expiry_date=nvl(expiry_date,sysdate) to set to sysdate if this record has not already been expired on all records where the outer join fails.
Further consideration: what do you do if the record is re-inserted into the source table? create a new dimension key? Or remove the expiry date?
But I will say that I am not a fan of deleting records in most circumstances. What do you do if you discover a calculation error and need to fix that and republish historical cubes? Without the historical data, you lose the ability to do things like that. -
Best way to obtain records that are NOT in another table
I have two rather large tables in oracle. An Account table that has millions of rows. Each account may be enrolled into a particular program and therefore can also be in an Enrollment table, also with millions of rows. I'm trying to find the most optimal way to find any accounts in ACCOUNT that are NOT in the Enrollment table.
I was doing something like this:
select /*+ index(ACCOUNT idx_acct_no) */
a.acct_no
from ACCOUNT a
where a.acct_no not in (Select e.acct_no from ENROLLMENT e);
This takes a VERY long time to execute, even though I am using the index.
I even tried to use the PK on the ACCOUNT table, as it is also a FK on the ENROLLMENT table as such:
select a.acct_no
from ACCOUNT a
where a.id not in (Select e.id from ENROLLMENT e);
this too takes too long to get back (if at all).
Is there a better way to do this selection please?Well if you have the energy to type in the whole list, the syntax you've given will work, unless you blow the permitted number of elements.
But a practical solution would be to turn the list into a table. You still haven't got the hang of this "giving us enough information" concept, so let's presume:
(1) you're on a version of the databasse whoch is 9i or higher
(2) you have this list in a file of some sort.
In which case use an external table or perhaps a pipelined function to generate output which can be used in a SQL statement.
If neither of these solutions works for you please provide sufficient information for us to answer your question correctly. Your future co-operation is appreciated.
cheers, APC -
"The new table link contain TargetFieldNames that are not valid?
I am designing a report based on a sql stored procedure with 3 parameters required. I have a parameter that I would like to make dynamic based on an "Item" table for multiple selections.
I keep getting this error when I run the report
Prompting failed with the following error message: 'List of VAlues failure: fail to get values. (Cause of error: the new table link contains TargetFieldNames that are not valid. Error source: prompt.dll
Error code: 0x8004380d
Can someone point me to an example or tell me if this even possible to do?
Edited by: SHARON SCHMIDT on Feb 17, 2009 3:16 PMHi Sharon,
Searching for the error message got many KBase but I hope referring to the following would help you:
1211133 - Using parameters to select one, some or all values in a record selection formula
1220118 - Error: "List of Values failure"prompt.dll Error code: 0x8004380D"
Regards,
Sheeba -
Delete records from tableA which are not in tableB
Table A contains milions of records which is the best way to delete records from tableA which are not in tableB
delete from tableA where empno not in (select empno from tableb)
or
delete from tableA where empno not exists (select empno from tableb
where b.empno=a.empno)
any helpHi
If you can do this, do with this:
create table tableC
as select a.*
from tableA a,
(select empno from tableA
minus
select empno from tableB) b
where a.empno = b.empno;
drop table tableA;
rename table tableC to tableA;
Ott Karesz
http://www.trendo-kft.hu -
Omit notes during MIDI recording that are not in defined scale
I'm looking for a way to do the following in Logic, but am not sure how to set this up. I want to be able to:
1. Create a new midi track
2. In selected midi track, select a scale (for example, Pentatonic Minor)
3. Press record
4. During recording, only notes played from Pentatonic Minor scale would "register" (make a sound) and be recorded. All other notes pressed on midi controller that are not in Pentatonic Minor would not "register" nor be recorded in the sequencer.
Additionally helpful would be that in the piano roll sequencer after recording, I could only drag notes up or down along the Pentatonic Minor scale. In other words, I would not be allowed to drag a recorded note to another note that is not in Pentatonic Minor. If a note was dragged onto a "disabled" note, it would automatically snap to its nearest neighbor note in the Pentatonic Minor scale. Additionally useful would be to have all disabled notes (notes that are not in the Pentatonic Minor scale) appear to be disabled (grayed out) in the piano roll sequencer.
If this is not possible, is there any feature in Logic that will get me close to doing what I want? If not, is there any other sequencer that does this? I know this is something I could probably do in Max, but I was hoping to be able to do it in Logic. Thanks.Patch this between the PhysicalIn and the SequencerIn in the Environment:
!http://home.arcor.de/fuzzfilth/Other/mod.png!
Get it here:
http://home.arcor.de/fuzzfilth/Other/Modulator.zip
Christian -
Does anyone know of a type of microphone that will work with my computer to record quality v
oices that do not sound hollow? Are there any tricks?
Thank you very much for any help with this
GregRyclark, true, but I would still go with a Shure SM-58. On amazon, you can get it with for only $100, which is a great deal (it's usually around $200), and you can purchase a xlr to usb separately (shure's is really expensive, $84)
http://www.amazon.com/Shure-SM58LC-Cardioid-Dynamic-Microphone/dp/B0001ZWBL0/ref=sr_1_fkmr 0_1?ie=UTF8&qid=1279480531&sr=8-1-fkmr0 -
How do I include those empployee numbers that are not 8 digits?
Hello all again.
My script currently doesn't find those employee numbers that are NOT 8 digits (some emp nos are 6, 7, 9) when doing comparisons. I've tried LPAD but it still doesn't find. Can anybody suggest a reason for this? I can post my whole script if you want but basically it doesn't match record in my temp table (SU_TEMPLOYEE_DETAILS):
SELECT std_hire_date, std_last_name, std_sex, std_date_of_birth,
std_email_address, std_emp_status,
LPAD (std_employee_number, 8, '0') std_employee_number,
-- std_employee_number,
std_first_name, std_marital_status, std_middle_names,
std_nationality, std_title, std_national_identifier,
std_address_line1, std_address_line2, std_address_line3,
std_address_line4, std_post_code, std_telephone_1, std_country,
std_location_id, LPAD (std_supervisor_number, 8, '0') std_supervisor_number
FROM SU_TEMPLOYEE_DETAILS
WHERE std_employee_number = :p_emp_number..with the existing record in Production instance:
SELECT DISTINCT per.person_id, per.business_group_id, per.last_name,
per.start_date, per.date_of_birth, per.email_address,
--LPAD (per.employee_number, 8, '0') employee_number,
per.employee_number,
per.first_name,
per.marital_status, per.middle_names, per.nationality,
per.national_identifier, per.sex, per.title,
padd.address_id, padd.primary_flag, padd.address_line1,
padd.address_line2, padd.address_line3,
padd.town_or_city, padd.postal_code,
padd.telephone_number_1, paas.assignment_id,
paas.assignment_number, paas.object_version_number,
paas.effective_start_date, paas.effective_end_date,
paas.job_id, paas.position_id, paas.location_id,
paas.organization_id, paas.assignment_type,
paas.supervisor_id, paas.default_code_comb_id,
paas.set_of_books_id, paas.period_of_service_id
FROM per_all_people_f per,
per_all_assignments_f paas,
per_addresses padd
WHERE padd.person_id(+) = per.person_id
AND paas.person_id(+) = per.person_id
AND per.employee_number LIKE 'C%'-- :p_emp_number
AND per.national_identifier = :p_ni_number
AND REGEXP_LIKE(per.employee_number, '[[:alpha:]]');The Employee Number is 7 digits long (0000016). But I need the script to match its record where it may be 000016 or 00000016 in Production. Is this possible?
Many thanks for looking..
StevenJackyWhite wrote:
My script currently doesn't find those employee numbers that are NOT 8 digits (some emp nos are 6, 7, 9) when doing comparisons. I've tried LPAD but it still doesn't find. Can anybody suggest a reason for this? I can post my whole script if you want but basically it doesn't match record in my temp table (SU_TEMPLOYEE_DETAILS):
The Employee Number is 7 digits long (0000016). But I need the script to match its record where it may be 000016 or 00000016 in Production. Is this possible? I would like to use the TRIM Function here rather than a simple LPAD (with hard coded length) especially if the length of the column std_employee number varies based on the leading zeroes. Something like:
SQL> WITH test_tab AS
2 (SELECT '000016' col
3 FROM DUAL
4 UNION ALL
5 SELECT '10000016'
6 FROM DUAL
7 UNION ALL
8 SELECT '00000016'
9 FROM DUAL)
10 -- "end of test data "
11 SELECT col, TRIM (LEADING '0' FROM col) changed_col_2
12 FROM test_tab
13 /
COL CHANGED_
000016 16
10000016 10000016
00000016 16
3 rows selected.
SQL> variable param VARCHAR2(30);
SQL> exec :param := '00016';
PL/SQL procedure successfully completed.
SQL> WITH test_tab AS
2 (SELECT '000016' col
3 FROM DUAL
4 UNION ALL
5 SELECT '10000016'
6 FROM DUAL
7 UNION ALL
8 SELECT '00000016'
9 FROM DUAL)
10 -- "end of test data "
11 SELECT col, TRIM (LEADING '0' FROM col) changed_col_2
12 FROM test_tab
13 WHERE TRIM (LEADING '0' FROM col) = TRIM (LEADING '0' FROM :param)
14 /
COL CHANGED_
000016 16
00000016 16
2 rows selected.
SQL> exec :param := '016';
PL/SQL procedure successfully completed.
SQL> WITH test_tab AS
2 (SELECT '000016' col
3 FROM DUAL
4 UNION ALL
5 SELECT '10000016'
6 FROM DUAL
7 UNION ALL
8 SELECT '00000016'
9 FROM DUAL)
10 -- "end of test data "
11 SELECT col, TRIM (LEADING '0' FROM col) changed_col_2
12 FROM test_tab
13 WHERE TRIM (LEADING '0' FROM col) = TRIM (LEADING '0' FROM :param)
14 /
COL CHANGED_
000016 16
00000016 16
2 rows selected.
SQL> So your where clause will become something like:
WHERE TRIM (LEADING '0' FROM std_employee_number) =
TRIM (LEADING '0' FROM :p_emp_number)Hope this helps.
Regards,
Jo -
Join 2 tables which are not related with any primary-foriegn key constraint
Hello,
How to join 2 tables which are not related with any primary key foreign key constraint.
Ex.Consider Table A has 5 columns->A_ID,A_Name,A_Address,A_City,A_Pin(Total 10 rows)
Table B has 5 columns->B_ID,B_Name,B_Adress,B_City,B_City(Total 30 rows)
From both the table i want the data,which i need to use in curosr to display finally as "Address Label".
Both the table are entirely different,but there can be some names of Table A which may come in Table B also,if the name,address and city is also same.That means same person in both the table.
So finally i want total number of distinct records(distinct data of Table A which is not in B+all the data of table B) to come under Address Label.
How can i write the select query for this condition?
Thanks
SwapnaHi, Swapna,
user11018268 wrote:
Hello,
How to join 2 tables which are not related with any primary key foreign key constraint.
Ex.Consider Table A has 5 columns->A_ID,A_Name,A_Address,A_City,A_Pin(Total 10 rows)
Table B has 5 columns->B_ID,B_Name,B_Adress,B_City,B_City(Total 30 rows)
Both the table are entirely different,but there can be some names of Table A which may come in Table B also,if the name,address and city is also same.That means same person in both the table.I think you want a UNION, not a join.
If you have 10 rows in table_a, and 30 rows in table_b, then
SELECT A_ID, A_Name, A_Address, A_City, A_Pin
FROM table_a
UNION
SELECT B_ID, B_Name, B_Adress, B_City, B_City
FROM table_b
ORDER BY 2, 4
;will produce up to 40 rows; 40 if there are no duplicates. (UNION implies DISTINCT.)
The corresponding column types should be similar, if not exactly the same.
There's no problem if A_Name is VARCHAR2 (50) and B_Name is CHAR (30).
However, there will be a problem if A_ID is a NUMBER and B_ID is a TIMESTAMP.
You must have the same number of columns in all branches of the UNION.
If you want an ORDER BY clause, put it at the very end, after the last branch of the UNION.
You can use positional notation (where 2 means the 2nd column) like I did, or you can use names from the first prong of the UNION (such as A_Name).
From both the table i want the data,which i need to use in curosr to display finally as "Address Label".
So finally i want total number of distinct records(distinct data of Table A which is not in B+all the data of table B) to come under Address Label.I'm not sure what your mean about "Address Label".
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables, and the exact results (formatted) that you want from that data.
You can concatenate all 5 columns into one VARCHAR2 column, if you want to.
You'll probably want to use RPAD (or simillar functions) to make the output line up nicely.
If any of the columns are not strings, use TO_CHAR to make string versions of them.
For example:
SELECT TO_CHAR (A_ID, '9999999')
|| ' ' -- leave a little space between the left-justified a_id and the right-justified a_name
|| RPAD (A_Name, 25)
|| RPAD (A_Address, 50)
...Edited by: Frank Kulash on Nov 14, 2009 10:11 AM -
How to select all the people that are not in any equipe ?
Hi,
I have a nice SQL expression that gives me as a result all the "AGENTS" (people) that are working in an EQUIPE (a team)
select a."AGENT_ID",
a."NOM" || ' ' || a."PRENOM" "Nom",
c.libelle "Equipe",
a."DATE_EMBAUCHE" "Date embauche",
a."DATE_DEBAUCHE" "Date débauche"
from OBSERVATOIRE."AGENT" a,
observatoire.equipe_agents b,
observatoire.equipe c
where a.agent_id = b.agent_id
and b.equipe_id = c.equipe_id
order by nom
Now, how to select all the agents that are NOT working in any "EQUIPE" (team) ?
I have tried but could not succeed !
Thank you for your kind help.
ChristianChristian from France wrote:
It is not working because the table EQUIPE_AGENTS does not contains a row if the agent is not into any equipe.
CREATE TABLE "OBSERVATOIRE"."EQUIPE_AGENTS"
( "EQUIPE_AGENTS_ID" NUMBER NOT NULL ENABLE,
"EQUIPE_ID" NUMBER NOT NULL ENABLE,
"AGENT_ID" NUMBER NOT NULL ENABLE)
CREATE TABLE "OBSERVATOIRE"."AGENT"
( "AGENT_ID" NUMBER NOT NULL ENABLE,
"GRADES_ID" NUMBER NOT NULL ENABLE,
"NOM" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"PRENOM" VARCHAR2(50 BYTE),
"DATE_EMBAUCHE" DATE NOT NULL ENABLE,
"DATE_DEBAUCHE" DATE)
The only way to "know" if an agent is not into any equipe (team) is to search into the EQUIPE_AGENTS table, and if we do not find the ID of the agent into this table, then we know that this agent is not into any EQUIPE (team).
I don't know ho to translate this into SQL.And that's what my query does. It uses an OUTER JOIN so that a result record is returned whether or not there is a record in EQUIPE_AGENTS. And the check for EQUIPE_ID is NULL restricts the result set to those where there IS NOT a record in EQUIPE_AGENTS.
A more traditional way would be to use NOT IN or NOT EXISTS clauses, but they can prove inefficient. -
Can EJB 3.0 beans be used with tables that do not have a primary key?
Can a EJB 3.0 persistence bean be used with tables that do not have a primary key defined? I am building a test application based on the HowTo - Building EJB 3.0 Faces App paper posted after Openworld (schalk). The issue I am running into when trying to run the application is: Exception Description: Entity class [class com.persistence.Rpthead] has no primary key specified. Note: I get a simular error when using toplink directly.
The tables I am binding to do not have primary keys defined. They use unique constraints to manage the table integrity.
Is it possible to use EJB 3.0 on tables without a primary key? If not, are there plans to support this in the future?The spec requires a primary key Id annotation. I will take your suggestion to EJB 3.0 expert group.
Can you also send an email to [email protected] with your requirement?
-Debu
Maybe you are looking for
-
Hi, I am required to create a large number of input forms. For each form item, there is a heading to describe what the form item collects and also additional descriptive text, such as units of measurements etc. I intend to create a report that will l
-
Print or Submit Depending on if PDF has digital signature
hello everyone!! i have a quick question and please let me know if i am posting this in the wrong area. i have a pdf form created in Acrobat 7 but we need to reader rights enabled so I have since them downloaded acrobat pro 9 and revamped it. it wor
-
G/L account no assigned cheque numbers in Document Overview screen (FB03)
Hi there, I currently have an issue wherein cheque numbers are not assigned on the document overview - display screen. Payment run and Cheque run have been initiated. Checking on SAP table PAYR-CHECT, cheque number is assigned to the relevant doc n
-
Dropped ipad. Now the screen is fuzzy but apps etc can be opened but are in decipherable
Dropped ipad 2 Now screen is all fuzzy but apps can be vaguely seen and can be open but nothing is decipherable.
-
hi, I have added a push button in the form. I have written $record.CONTROL_PARAM.ISR_EVENT = "USER_EVENT_CHECK", as i wanted to fill up some fields related to a position upon entering the same. Wanted to know what else should be done, so that when t