0

I have a little problem that I can´t solve. It´s really simple, but I just can´t figure it out and have search some time but not found any good answers.

I have two tables:

Transaction
t_nr (Primary)   a_nr     quantity
 1                1          10
 2                2          10 
Customer
c_nr (PRIMARY)  name        city
 1              Mario       Tokyo
 2              Luigi       Beijing 

And want to insert values from the two above into another table with one query looking Account a_nr (primary) c_nr

Problem is that when just making a regular select-from-statement it returns:

a_nr     c_nr
 1        1
 1        2
 2        1
 2        2

i.e. not just merges them together in the account table.

a_nr     c_nr
 1        1
 2        2

How do I do this?

5
  • 1
    What is your SELECT? Commented Mar 27, 2013 at 22:42
  • Instead of selecting *, type in only the fields you want. a_nr, c_nr, desired_column1, desired_column2, desired_column3, etc... Commented Mar 27, 2013 at 22:42
  • what I have tried is: Commented Mar 27, 2013 at 22:43
  • insert into account (a_nr,c_nr) select transaction.a_nr, customer.c_nr from transaction, customer Commented Mar 27, 2013 at 22:47
  • Thanks Explosion Pills! Commented Mar 27, 2013 at 22:48

1 Answer 1

1

Does a_nr correlate to c_nr (are they equal)?

If so,

insert into account (a_nr,c_nr)
SELECT transaction.a_nr, customer.c_nr from transaction, customer
WHERE transaction.a_nr = customer.c_nr

Although this seems completely pointless to only insert two values that are the same.

What is the desired output of Account?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.