INSERT INTO

For the append query INSERT INTO <target>,the <target> is described as "The name of the table or query to append records to.".What I cannot understand is how can the <target> be a query?Besides,how to insert records in the middle,rather than at the end?
EXwithRajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hongjunCommented:
post ur sql
0
EXwithRajAuthor Commented:
I can't understand why you need some SQL.My query is related to the "target" part of the INSERT INTO statement.It's described in the help as either a table or a query.If it's a query then how can INSERT INTO  be used?
0
mmusanteCommented:
> Besides,how to insert records in the middle,rather than at the end?

Just sort the data how you need, You can add a 'order' field and set it to a value
so the data you insert will be in the middle if you get your data ordered by the
'order' field.


Wich DB are you working with?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mmusanteCommented:
> What I cannot understand is how can the <target> be a query

May be that your insert will be done only on the table
subset defined by the query
0
wael_tahonCommented:
A simple insert statement:

(1) Insert into YourTableName( Column1, Colmn2, Colmn3)   Values(Valu1, Valu2, Valu3)

This insert one row in the "YourTableName"

(2) Insert into YourTableName( Column1, Colmn2, Colmn3)  Select Col1, Col2, Col3 From AnotherTableName where Somthing=2

This insert multible rows in the "YourTableName" from the selection returned from "AnotherTableName "


0
EXwithRajAuthor Commented:
wael_tahon,you've not understood the requirements of my query at all.The kind of solution you've provided is not what I require.In fact,you've strangely assumed that I am ignorant of INSERT INTO.Sorry to disappoint you - but I am NOT!
       mmusante  ,on the other hand has understood me.But,mmusante,your solution is vague,therefore,I am unable to gather how it'll work.Furthur input from you is required.
0
mmusanteCommented:
Sorry but your question is vague too!

Wich DB are you working with? In both MSSQL-Server and Oracle the <target> for the INSERT INTO steatment is a table or a VIEW (not a query). I'm supposing that you are working with Access (where views are called 'query') but I'm not sure about this.

Views (and queries in Access) if they are UPDATABLE may work like tables and can also be updated.

A view is updatable if it mantain a one-to-one relation vith all origin tables so if you update the view the DBMS can update the data in the tables of origin.
0
Jeff CertainCommented:
The answer is this: some queries are updatable. Depending on the database you are using, the requirements for a query/view to be updatable vary. Generally speaking, the query must contain enough information to identify every record that must be updated (i.e. the primary keys from all tables involved in the query). In addition, the query must contain all not nullable fields from all tables in the query. Under these conditions, you can update the query.
0
Arthur_WoodCommented:
this part of your question:"how to insert records in the middle,rather than at the end?" has no meaning.  The concept of Beginning, Middle  or End has no meaning is a Relational Database.  There is no Beginning, no Middle, and no End.

The physical oder of records is totally without meaning, or relevance.  That is one of the advantages of the relational design, which totally abstracts the physical location of the records, from the display of the records.  You can change the display order to almost anything you want, by using a Query and an appropriate Order BY clause.

AW
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EXwithRajAuthor Commented:
mmusante,you guessed it right - I am using MS Access.I also agree that in MS Access,a View & Query,are the same.
    Arthur Wood,I totally agree with you.The idea of inserting a record in the middle of a database doesn't sound logical at all.
0
Arthur_WoodCommented:
not only is it not logical, it can't be done.  There is no 'middle' in a relational database.

AW
0
Arthur_WoodCommented:
and if you agree, then why did you ask the question (about inserting in the middle) in the first place?

AW
0
EXwithRajAuthor Commented:
Arthur Wood,I simply asked the question out of curiosity - and certainly not to waste your time.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.