3

I have two tables and an associative table between them (let's call them Tab1, Tab2 and ATab).

Tab1 and Tab2 have those very same fields (for example purpose) :

  • Id.
  • Name.

In my ATab, I want to insert record to associates Tab1 and Tab2 with their Ids.

In order to do so, I would like to write my query in a sql script that say something like :

I can manage to do something like :

INSERT INTO ATab(Tab1Id, Tab2Id) 
SELECT Tab1.Id, ????? 
FROM Tab1 WHERE Tab1.Name='Foo';

But I'm selecting only the Foo record of my first table...

How would I manage to perform a "double" where clause ? Is it possible ?

epoch
  • 16,396
  • 4
  • 43
  • 71
Andy M
  • 5,945
  • 7
  • 51
  • 96

1 Answers1

6

by using AND

INSERT INTO ATab(Tab1Id, Tab2Id) 
(SELECT Tab1.Id, Tab2.Id
FROM Tab1, Tab2 WHERE Tab1.Name = 'Foo' AND Tab2.Name = 'Bar')
epoch
  • 16,396
  • 4
  • 43
  • 71