473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Insert DISTINCT Records

All

I want to run an insert query to insert new records but only distinct one's.Is there any direct query syntax to do that.I have an idea to write a function to check the records one by one but that will be cumbersome if dataset is large.any other ideas??


thanks
Sree
Jan 27 '09 #1
4 15958
DonRayner
489 Expert 256MB
While in the query design view , click Properties on the toolbar to display the query's property sheet.

To prevent showing duplicate records in a query based on fields in the underlying table, Set the UniqueRecords property to yes. This would be SELECT DISTINCTROW if you were writing the SQL in VBA

To prevent showing duplicate records in a query based on fields in the query design grid, Set the UniqueValues property to yes. This would be SELECT DISTINCT if you were writing the SQL in VBA.
Jan 27 '09 #2
DonRayner
But my query is in the coding part and moreover its not a selection query its an insertion query.


thanks
Sree
Jan 27 '09 #3
DonRayner
489 Expert 256MB
@buddydasari
Sree,

Write your insert query and add either DISTINCT or DISTINCTROW after the SELECT statement. Here is an example of one of my own insert queries.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO t_affectedJobs ( JobNumber, IssuedQuanity, IssuedDate, JobStatus, NCMRIdent )
  2. SELECT DISTINCT dbo_Material_Req.Job, -[Quantity] AS PickQuantity, dbo_Material_Trans.Material_Trans_Date AS Expr1, dbo_Job.Status, Forms!t_NCMaterial!idholder AS Expr1
  3. FROM dbo_Material_Trans, dbo_Job RIGHT JOIN (dbo_Material INNER JOIN dbo_Material_Req ON dbo_Material.Material = dbo_Material_Req.Material) ON dbo_Job.Job = dbo_Material_Req.Job
  4. WHERE (((dbo_Material.Material)=[Forms]![f_NonConformance_add]![NCBatchNumber]) AND ((dbo_Material_Trans.Lot)=[Forms]![f_NonConformance_add]![MaterialLotNumber]) AND ((dbo_Material_Trans.Tran_Type)="issue"));
  5.  
Jan 27 '09 #4
NeoPa
32,556 Expert Mod 16PB
@buddydasari
So you have two options. Both of which Don has already covered :
  1. Change your SQL in the way indicated. Adding DISTINCT or DISTINCTROW (according to your needs) as a predicate after the SELECT keyword.
  2. Create the INSERT (append) query in the QBE grid and change the same properties as you would in a simple SELECT query.
    When happy with the query use the SQL view to copy the resultant (working) SQL to your code.
Jan 27 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: soni29 | last post by:
hi, i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like: Table1: (id, name, street, city, zip, phone, fax, etc...) about 20 more...
1
by: hoonew | last post by:
I need to do in SQL the following psuedo-code, and I'm stuck: IF ((COUNT(*) FROM a WHERE column_a=1)>0) THEN INSERT INTO TABLE b ENDIF
11
by: Hi5 | last post by:
Hi, I am new to access I usedto work in Oracle and Mysql. I am after a way that enables me to populate a database I designed in access with lots of data which can be sorted in excel sheets, ...
5
by: Fred Zuckerman | last post by:
Can someone explain the difference between these 2 queries? "Select Distinct id, account, lastname, firstname from table1" and "Select DistinctRow id, account, lastname, firstname from table1" ...
2
by: Frank van Vugt | last post by:
Hi, Not exactly a showstopper, but I noticed this behaviour: db=# create table f1 (id int, value int); CREATE TABLE db=# insert into f1 select 1 as id, null; INSERT 25456306 1
1
by: new | last post by:
I am building an effective dated file that shows results to date. In part 1 of the select I I process a larges set of input and genrate records for each date in the processing period for which...
2
by: mivey4 | last post by:
Okay I have 2 tables: Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes) Table B - holds a distinct list of current serial numbers...
6
by: eighthman11 | last post by:
Hi everyone: Using Sql Server SQL 8 I'm trying to INSERT records into a "can software package" batch table. I have a work-table that mimics the batch table. After manipulating the records in...
4
by: omnittha | last post by:
I would like to pull unique records of a SINGLE column but not the other related columns. When I use DISTINCT, it pulls up all the records which are unique across the columns. Here is the code.......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.