Place an Insert Statement into a Select Statement

牧云@^-^@ 提交于 2019-12-12 04:07:00

问题


I have read the other questions and all of the posted comments/answers to questions that are similar to this one. None of them seem to answer this question directly.

I am wanting to know if there is a way to either concatenate or place an INSERT, DELETE or UPDATE statement into a SELECT statement.

If so how? Could this be done by using a derived table function or a subSelect statement?

And example would be:


INSERT INTO Customer (name)
VALUES 'Test Name'

but place this into a SELECT statement

Example pseudo code:


SELECT *
FROM Customer
WHERE
Customer.name = (INSERT INTO Customer (name) VALUES 'Test Name')

The big thing here is getting the INSERT statement into the SELECT statement in an unconventional way.

Thank you and hopefully this will strike up some good conversation/ideas/results!

Reason for wanting to know this:

  1. Our current DBMS (Fishbowl) does not allow us to use an UPDATE, DELETE or INSERT statement with is SQL compiler and we are wanting to mass alter our fields/clean up our tables.
  2. To know if it is possible

回答1:


You may have a select within an insert but not the other way around.

A select within an insert statement could be used to copy values from a table to another. (You are just writing into a table after a read from another)

But an insert within a select doesn't make sense! What are you going to insert when you are running a select from a table(or just reading data)?(how is it possible to write when you are only allowed to read?)

Your situation, if you don't have access to run an insert then it doesn't matter where you put the statement, you just can't because you aren't allowed to!

But if you are talking about your query engine/database wrapper not allowing a direct insert, then its probably because it requires an application/program to insert data into to rather than just a query(as your engine doesn't already have the capability to perform that operation).



来源:https://stackoverflow.com/questions/37079467/place-an-insert-statement-into-a-select-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!