Amplify records

L

Lily

I have 10 records with 10 vehicles.
For example: Ford Explore
Honda Accord
.............


I have a table with 100 zipcodes.
My question is how can I amplify the 10 Vehicles by 100 zipcodes to generate
10*100 records.

I mean: 48152 Ford Explore
48152 Honda Accord
...................

44552 Ford Explore
44552 Honda Accord
....................


44444 Ford Explore
44444 Honda Accord
..................

Thanks a lot!

Lily
 
D

David Portas

Lily said:
I have 10 records with 10 vehicles.
For example: Ford Explore
Honda Accord
.............


I have a table with 100 zipcodes.
My question is how can I amplify the 10 Vehicles by 100 zipcodes to generate
10*100 records.

I mean: 48152 Ford Explore
48152 Honda Accord
...................

44552 Ford Explore
44552 Honda Accord
....................


44444 Ford Explore
44444 Honda Accord
..................

Thanks a lot!

Lily

Try:

SELECT z.zipcode, v.vehicle_name
FROM zipcodes AS z, vehicles AS v ;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
 
S

Sylvain Lafontaine

Use a Cross Join:

select * from Vehicles CROSS JOIN ZipCodes

You will get the cartesian product of both tables.
 
L

Lily

Thanks a lot, It works!

Sylvain Lafontaine said:
Use a Cross Join:

select * from Vehicles CROSS JOIN ZipCodes

You will get the cartesian product of both tables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top