Appending And Deleting Entries In Table

Jul 11, 2014

I have a question on appending and deleting entries in mysql table. This is my sample table.

table name: details

id_name | model | mode | media| first | end | id | level |
+--------------------+-------+---------+-----+-------+-------+--------+--------+
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14684 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14838 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15236 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |

[Code] ....

I have numerous entries of same id name belonging to same median number.However,I want to only retain the entries having the longest first and end position and discard the remaining entries

E.g. for id name ="PSK_30s1207681L002" AND median = 5 we have four entries

id_name | model | mode | media| first | end | id | level |
+--------------------+-------+---------+-----+-------+-------+--------+--------+
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14684 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 14838 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15236 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |

But I want to retain only the one having longest first and end points ie

| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |

Here ,since for id name ="PSK_30s1207681L002" & median = N we have only 1 entry I want retain that one.

My final output in mysql table should look like this.

id_name | model | mode | media| first | last | id | level |
| PSK_30s1207681L002 | -1 | 1 | 5 | 14026 | 15423 | 6255 | q |
| PSK_30s1207681L002 | 1 | 1 | N | 14026 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | 3 | 14033 | 15627 | 6255 | q |
| PSK_30s1207681L002 | -1 | 1 | T0 | 15550 | 16050 | 6255 | q |
| PSK_30s1189731L001 | -1 | 1 | 3 | 999 | 7531 | 9808 | c |
| PSK_30s1189731L001 | -1 | 1 | 5 | 6609 | 8257 | 9808 | c |

[Code] ....

Is there anything that I could do to append it?

View 1 Replies


ADVERTISEMENT

Trigger Is Deleting Entries In Audit Table?

Aug 30, 2013

The following is the trigger which create a row in the audit table when a single deletion is occurred.

ALTER TRIGGER [dbo].[TRG_Delete_tbl_attendance]
ON [dbo].[tbl_attendance]
AFTER DELETE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

[code]....

I am trying to create a trigger which should prevent the bulk deletion. The following is the trigger which I have written, it is preventing the bulk deletion. But the problem is, it is removing the single deletion entries in the audit table. I want audit table to hold back the single deletion entries without allowing the bult deletion

ALTER TRIGGER [dbo].[TRG_Delete_Bulk_tbl_attendance]
ON [dbo].[tbl_attendance]
AFTER DELETE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

[code]....

View 1 Replies View Related

Deleting Entries Under A Category That Is Being Deleted???

Sep 11, 2007

Hello.  I have a simple project using 3 tables: Categories, Subcategories, and Items.  I have just gotten my insert, edit, and delete functions to work, but I've noticed a problem I hope someone can help with:
 When I delete a certain category (lets say "Restaurants"), the subcategories and items that were in that category still remain in the database/table.  (If I delete "Restaurants", the subcategories "Italian", "Seafood", etc - as well as any items in those subcategories - are not deleted).
 So what would I need to do to delete any Subcategory that is in the deleted Category (shares a CategoryID) and then delete all Items in those Subcategories?
 For reference, all Subcategories in a Category have reference to that CategoryID, and all Items in a Subcategory have a "SubcategoryID" field.  I understand that I need to traverse the tables and remove all Subcategories with the CategoryID being deleted, but since the Items do not have a reference to the CategoryID, how would I delete those as well?
 
Thanks to whoever can help me out here!

View 4 Replies View Related

Deleting Unwanted Entries At The Subscriber .

Oct 8, 2002

Hello ,

I have created a publication from SQL Server 7.0 and subscribed the publication it to one of the SQL 2000 server std. edition .

Now there are some entries in the subscription list at the subscriber which need to be deleted .
The list shows the name of the publication , the database name and the date .

I wanted to know hoe can we delete those unwanted entries. If i select the entry and right click on it , there is no delete option .

Are those entries to be deleted from one of the tables at the subscriber or the publisher ? If yes, then what is the name of the table ?

Any ideas ?

Thank you very much .

View 3 Replies View Related

Deleting The Master Table Withour Deleting The Child Tables

Aug 9, 2007

Hi
i have to delete the master table data without deleting the child table records,is there any solution for this,  parent table has relation with the child table.
regards
vinod.t.v

View 9 Replies View Related

Stored Procedure To Copy Table 1 To Table 2 Appending The Data To Table 2.

Jan 26, 2006

Just wondering if there is an easy transact statement to copy table 1 to table 2, appending the data in table 2.with SQL2000, thanks.

View 2 Replies View Related

Appending Data On Same Clumn From Other Table

Apr 12, 2006

hi,

unfortunaly i have two tables where usernames are stored. in the one table the column is called 'remote_U' in the other 'remote_u' ... note the upper case

so want to generate listof all usernames and retrieve them in a single a column.

like
SELECT DISTINCT remote_U FROM table1 APPEND (SELECT DISTINCT remote_u FROM table 2)

i have tried joins and groups, but is not working. can i also do an alphabetical order after appending the second select? distinct is needed, 'cos one user may have more then one entry in the table, but may be also in both tables ....

View 4 Replies View Related

Appending Data To A Table But Not Duplicates

Jul 23, 2005

Hiya everyone,I have two tables in SQL 2000. I would like to append the contents ofTableA to TableB.Table A has around 1.1 Million Records.Table B has around 1 Million Reocords.Basically TableA has all of the data held in TableB plus 100,000additional records. I would only like to import or append these newadditional records. I have a unique index already setup on Table B.Any ideas pretty pretty please?Paul.Ps. (Have been messing around with DTS but get a unique violation error- Which is kinda what I want I guess, but would like SQL to ignore theerror and only copy the new data - if only)

View 9 Replies View Related

Creating Snapshot / Transactional Table By Appending

Feb 6, 2015

I am very new to SQL coming from a SAS background.

I work at a College where I am trying to create a table that basically stores application data so that I can record how many applications we had on a set day.

For example I want to run it say bi-weekly and create a date/time stamp for each row and then the next time it runs it appends to the original table but with the new date/time stamp.

I have managed to create the table and the date/time stamp but I'm not sure how to do the next stage.

This is not the best practice as the table will get "big" quite quickly (although we're only dealing in the hundreds in terms of rows). Ideally I'd have a more transactional database that only appends a record if there is a change i.e. the status of the application has changed from "Received" to "Interview" or similar.

I'm not sure how to copy and paste the code dynamically in this forum but this is what I have got so far (see below).

SELECT
CC.cc_name as Academy,
SUBSTRING(CC2.cc_reference,1,4) as Cost_Centre,
MD2.m_reference as Course,
MD2.m_name as Course_Name,
CAST(MD2.m_start AS DATE) as Start_Date,

[Code] ...

View 4 Replies View Related

Appending Records To The Existing MS SQL EXPRESS SERVER Table.

May 19, 2007

Dear All,I am Using  MS SQL EXPRESS SERVER .I have installed all tools available to Express Edition site. Now I have created my database on this .I have imported a table from my MS ACCESS database (Using ODBC Datasource).This table contains 10,000 records ,Now I want to append 1 more access Table(5500 records) to the existing table   having same fields.How to do this.Can any body tell me? Thanks and Regardsmukesh 

View 4 Replies View Related

No Further Entries Of A Value In Table

Mar 30, 2012

I have a table which stores phone numbers of a customer in a table.

Say this table is as below

CustomerName - PhoneNumber
Customer 1 - Phone number 1
Customer 2 - Phone number 2
Customer 2 - Phone number 3
Customer 3 - Phone number 4

What would be the best approach to prevent adding another entry against Customer 2. I should be able to add new customers and add multiple phone number against all other Customers. The restriction should be only against Customer 2.

View 4 Replies View Related

Getting Random Table Entries

Jan 20, 2008

Hi,I have a  form that should show 2 pictures based on table entries.I want those 2 pictures to be randomly selected based on a database table. So, my table has all the entries, and I want to pull out a random entry that has been approved to display it.Can someone help me with the sql query?I can do SELECT VoteId FROM tblVotes WHERE Approved=True..But how do I make selection a random one that changes every time the user gets another entry? 

View 2 Replies View Related

Entries In UPPER In A Table

Mar 27, 2001

Is there a way I can have all entries in a table automatically in caps once entered by user, import or any other way ?


Thanks a lot in advance.

-PFD

View 2 Replies View Related

How To Know The Order Of Entries In A Table

Jul 5, 2007

For example some data has entered into a table in a random manner i.e the pk filed value is not in a serial fashion.Is there any table or index that holds the entries of rows into a particular table as entered .

i.e
'some_table' has data like this

3,entry3
2,entry2
4,entry4
1,entry1

I want some DB table or Index that holds data like this about above 'some_table'

row_id .... .... ....
1
2
3
4

here 1 refers to entry of the first column in 'some_table' i.e 3,entry3
and so on...

View 2 Replies View Related

Duplicate Entries In The Resulting Table

Sep 20, 2007

Hi! I am joining 3 tables in SQL , I am getting the results I want exept it's duplicated. So the resultinmg table fom my stored procedure has 3 rows that have the same bulletin. How do I filter the storedprocedure to output only the rows that don't have duplicate entries for the column 'Bulletin' Thanks.
Here is my stored procedure:PROCEDURE [dbo].[spGetCompBulletins]
@Userid uniqueidentifier OUTPUT,@DisplayName varchar(200)
 
AS
 
SELECT *
FROM dbo.UserProfile INNER JOIN
dbo.bulletins ON dbo.UserProfile.UserId = dbo.bulletins.Userid INNER JOINdbo.Associations ON dbo.Associations.BusinessID = dbo.bulletins.Userid WHERE UserProfile.DisplayName=@DisplayName
and Userprofile.Userid = @Userid ORDER BY Bulletins.Bulletin_Date
Return

View 7 Replies View Related

Save DELETED Entries To New Table

Mar 23, 2008

Hi all
I would like to know if its possible to "Save" records when they get deleted.
For example: I have a table, tblUsers, with coulmns, UserID, Name, Surname, etc...
In VWD I've created a GridView which shows everything on a webpage. I've also added a confirm return('Are you sure you want to delete the user?') option in OnClientClick field. What i want to achieve is, have some sort of log file, or log table if you want to call it that, of which users has been deleted by the end user. So, in later stages, i can see who deleted who, when, where, etc... - by building a report or view.
All this should go to a seperate database or seperate table, it doesnt really matter.
My delete query:DELETE FROM [tblUsers] WHERE [UserID] = @UserID

View 9 Replies View Related

Prevent Duplicate Entries In A Table

Nov 11, 2003

I have an ASP.Net Web appplication with a Back-End SQL DB. There are 3 Tables; Users, Groups, and GroupMember.

The GroupMember table is used to link Users to Groups and consists of just two fields; userID and GroupID.

Here is a sample of some data:

User1 Group1
User1 Group2
User2 Group2
User3 Group1
User3 Group3

Users can belong to multiple Groups. However, you shouldn't be able to have the same user and group comobination more than once. for example:

User1 Group1
User2 Group2
User1 Group1

I can stop this kind of duplicate data entry by doing a lookup first (using asp.net) to see if the entry already exists but this seems cumbersome.

Is there a simpler way to prevent duplicate entries in a table using sql?

Thanks a lot,

Chris

View 3 Replies View Related

How Do I Should Temp Table Entries In SQL Debug Mo

Sep 5, 2007

I am troubling SQL stored procedures. The SP has temp table created to contain data. How can I populate the temp table in the SQL debug mode?

View 1 Replies View Related

Truncating Duplicate Entries In A Table

Sep 18, 2007

Hi,

I have a table with no primary key and i just want to see all the duplicate entries on the basis of two columns. Can anyone suggest me how should i go about it.

Can anyone provide me the syntax for the same?
I have only 1 table say ISSR_TBL and two columns using which i want to delete the duplicate ones. i.e. MIN and MAX.

Please help me out...

View 3 Replies View Related

Check Dupplicate Entries In Table

Feb 26, 2008

Helo everybody,

How can i find a dupplicate entry in one table?

View 9 Replies View Related

Searching For Entries In Subsequent Log Entries?

Dec 2, 2013

If I wanted to search for Jobs as a particular status (e.g. 0130) and wanted to keep the jobs at this status until it has reached 0500, 0125, or 0900 in it's subsequent status log entry, how can I write the SQL for it to achieve it?

I have the following SQL which searches for the Jobs at 0130, but don't know how to develop it further to search on the requirement above.

------ SQL -------
SELECT
job.job_number,
(SELECT MAX(jsl.job_log_number)
FROM job_status_log jsl
WHERE
job.job_number = jsl.job_number AND
jsl.status_code = '0130') as Last_Early_Warning_Status_Entry

[code].....

In the job_status_log table above, there is a job_log_number field which increments by 1 when there is a new status log entry.

View 1 Replies View Related

Periodic Removal Row Entries In A Data Table?

Mar 29, 2008

Hi everyone,
I am using this temporary data table which gets cluttered after certain time (table is used for registering data waiting for email confirmation).
Is there a possibility to empty a data table automatically every day (at a certain moment)?
Kind regards,Maxime

View 2 Replies View Related

Updating Table - Trigger Duplicate Entries

Jun 12, 2014

I got error while updating a table ,duplicate entries and trigger got fired ..so how to debug the trigger to know duplicate record.

View 1 Replies View Related

Resolving Duplicates Entries In Table Among 10 Databases

Feb 11, 2006

HiOur product uses MS-SQL Server 2000. One of our customer has 10installations with each installation stroring data in its own database.Now the customer wants to consolidate these databases into one and wealready have plan for that by consolidating one DB at a time. But firstthey want to find how many unique or duplicate entries they have acrossall the 10 databasesAssumptions:1. All the databases reside on the same server. (This is just anassumption, not the real environment at customer site)2. Databases can not be merged before it is found how many unique orduplicate rows exist.Table under consideration:Message(HashID PK,....)# of rows in Message table in each of databases: 1 MillionHere is my question: How can I find how many unique or duplicateentries they have across all the 10 databases. I easily find uniquerows for two databases with a query like this:SELECT COUNT(A.HasID) FROM db1.dbo.Message A LEFT OUTER JOIN ONdb2.dbo.Message B ON A.HashID = B.HashID WHERE B.HashID IS NULLHow can I do this for 10 databases. This will require factorial of 10queries to solve this problem.I will appreciate if someone can provide hint on this.RegardsAK

View 3 Replies View Related

How To Force Unique Entries In A Linking Table?

Jul 20, 2005

I have a table 'Group2Operation' that stores many to many relationsbetween the 'Group' table and the 'Operation' table (each group is haspermission to perform one or more of the available operations)PROBLEM=======I need to prevent duplicate entries being created. e.g. lets say thatin the 'Group2Operation' table a record links the 'editor' group tothe 'publish' operation. Should I prevent an administrator creating aduplicate of that record? (Otherwise deleting that permission willhave to be done twice or more for it to be effective)SOLUTION?=========So far I've done this with a trigger:CREATE TRIGGER Group2OperationDuplicates ON dbo.Group2OperationFOR INSERT, UPDATEAS UPDATE Group2OperationSET NoDuplicate = CONVERT(nvarchar(10),GroupID) + OperationTagThe 'NoDuplicate' unique index column in the Group2Operation tablestores a concatenation of the unique group and operation identifiers.So when an attempt is made to create a record, the trigger is fired.If there is a duplicate, this will mean a duplicate entry in the'NoDuplicate' column. As a result, the INSERT or UPDATE will fail andthe duplication will be prevented.WHAT DO YOU THINK?==================What do you think? Am I going about this in the right way? Is atrigger a good way to do this or should I rely on application logic toprevent duplicates?Any help appreciated by this db novice.John Grist

View 2 Replies View Related

Transact SQL :: Find All Duplicate Entries In Table

Jun 11, 2015

Someone ran an update statement multiple times so their are multiple entries in the table.  What is the quickest way to track down the multiple entries?  I would only want to see where timein and timeoff exist in the table multiple times for the same id.  So this would be a duplicate

EntryID -- ID  -- timein -- timeoff
1487   11     2015-05-05 16:33:23   2015-05-05 18:45:26
1623   11     2015-05-05 16:33:23   2015-05-05 18:45:26

View 7 Replies View Related

Writting Trigger Or Procedure To Delete Duplicate Entries In A Table?

Sep 3, 2007

I am using Sql Server 2000.
I have a customer table with fields - CustId, Name, Address, City, StdCode, Phone.
I used to insert entries in this table from an excel file.
One excel file will contain thousands of customer.
In this table combination of StdCode and Phone should not be repeated.
If I do it in my VB.Net coding.then application gets drastically slow.
So I want to write a procedure or trigger for this.
Here what I will do, I will send all records into database then this trigger or procedure will check for
any existing entry of combination of StdCode and phone. If entry exists then this will delete new entry
or will not allow this new entry.
Is this possible to do using Trigger or stored procedure?

View 5 Replies View Related

SQL Server 2014 :: Find Multiple Entries In Two Fields One Table?

Sep 12, 2014

I am trying to find books which have the same title and publisher name as at least two other books and need to also show the book ref (ISBN number). I have the below script so far:

SELECT isbn, title, publishername
FROM book
WHERE title in (SELECT title
FROM book
GROUP BY title
HAVING count(title)>2 or count(publishername)>2)
order by title;

This is a snap shot of the output:

ISBN Title Publishername
0-1311804-3-6 C Prentice Hall
* 0-0788132-1-2 C OSBORNE MCGRAW-HILL
* 0-0788153-8-X C OSBORNE MCGRAW-HILL
* 0-9435183-3-4 C Database Development MIS
* 1-5582806-2-6 C Database Development MIS

[Code] ....

What I should be seeing is only the ones I have put an * next to. What am I missing from the scrip?

View 3 Replies View Related

Retrieving Data From Table With 7 Million Entries Takes Time

Jul 25, 2007

Can anyone help me on this...
when i select data from table using select statement it takes huge amount of time....The table contains 7 million entries and when i select by mentioning a criteria it takes around 45 secs..The system has 4GB RAM and Dual Processing CPU. The select statement does not contain any grouping and all..

Will it take this much time to retrieve data.?.
The table does include an indexed field,
So can anyone help me on the different things i can do to make the retrieval faster?

Andy

View 5 Replies View Related

Deleting A Table

Nov 9, 1998

i have a table that i think is bad -
how do i delete the table?
also i want to copy this same table from another database -
can i use enterprise manager to copy the same table in place of the deleted table?

View 1 Replies View Related

Deleting Row From Table

Jun 17, 2008

Hi guys,

I have a table which consist of 6,185 rows and from this table I want to delete 427 rows. I have placed the 427 rows in a separate table. So how do I delete these 427 from the original table(6185 rows).

I should also mention that the table does not have a primary key so I was thinking about something like this but it didn't work


delete o.CardNumber
,o.ref_no
,o.tran_date
,o.tran_val

from test6185 o

where exists (select h.CardNumber
,h.ref_no
,h.tran_date
,h.tran_val
from test427 h
where( h.ref_no=o.ref_no and
h.CardNumber = o.CardNumber and
h.tran_date =o.tran_date and
h.tran_val =o.tran_val
))

order by cardnumber


Thank much for any help

View 3 Replies View Related

Deleting From SQL Table Using Two Arguments

Nov 7, 2007

I am trying to delete from a SQL table using two arguments, I currently use the following on the aspx page: <ItemTemplate><asp:LinkButton ID="cmdDeleteJob" runat="server"  CommandName="CancelJob" Text="Delete" CssClass="CommandButton" CommandArgument='<%# Bind("Type_of_service") %>'                       OnClientClick="return confirm('Are you sure you want to delete this item?');"></asp:LinkButton></ItemTemplate>  and then I use the following on the aspx.vb page: If e.CommandName = "CancelJob" Then                Dim typeService As Integer = CType(e.CommandArgument, Integer)                Dim typeDesc As String = ""                Dim wsDelete As New page1                wsDelete.deleteAgencySvcs(typeService)                gvTech.DataBind()  I need to be able to pick up two CommandArguments. 

View 4 Replies View Related

Deleting Columns From Table

May 26, 2006

in sql server 2000, I have a table that I have to write a script for to delete several columns in this table.  I am finding that I have to use alter or drop keywords or a combination of the two but not sure because I have not done this before.  I am googling this but finding all kinds of other information that I dont' need to know.
I dont have rights on this table so I cannot do this manually.  I have to create the script and send it on to someone else.
If anyone can provide a good script example that I can use to delete unwanted columns it would be a great thing.  Thanks.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved