Microsoft Access 2007, SQL Query - How to insert values from another table?
-
Would appreciate any help :) I have two tables in Access and I am trying to populate them. The first table is artist: name birth death nationality styles I have populated these fine. The next table is my paintings table: painting_id title media height width artist My SQL query at the moment is: INSERT INTO paintings VALUES ("P01", "The Opening of Waterloo Bridge", "Oil on canvas", 1308, 2180, SELECT name FROM artist WHERE name = "John Constable"; As you can see, all of the values apart from Artist will fit in as the name of the artist is from another table. Is there a way of adding it in? When creating the painting table I have added a reference to artist : artist VARCHAR(20) REFERENCES artist(name) Thanks in advance :)
-
Answer:
Two ways to do this - INSERT INTO Paintings VALUES ( "P01", "The Opening of Waterloo Bridge", "Oil on canvas", 1308, 2180, ( SELECT name FROM artist WHERE name = "John Constable" ) ) OR INSERT INTO Paintings SELECT "P01", "The Opening of Waterloo Bridge", "Oil on canvas", 1308, 2180,name FROM artist WHERE name = "John Constable" -- In 'thoughts'... Lonely Rogue.
Aahmed at Yahoo! Answers Visit the source
Other answers
This seems to be a badly designed database. Surely the Artists table should have a unique ID field e.g. artist_ID? Additionally the Painting table should have the artist_id rather than the artist field?
ray_diator
Related Q & A:
- How can I optimize this dynamic SQL query in oracle with PL/SQL?Best solution by docs.oracle.com
- How to insert data from one table to another?Best solution by Stack Overflow
- How to convert sql query to Hibernate Criteria query?Best solution by Stack Overflow
- How to convert my SQL query to MS Access query?Best solution by Stack Overflow
- How to convert SQL query to LINQ query?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.