querry problem

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 1
Reputation: sebaz is an unknown quantity at this point 
Solved Threads: 0
sebaz sebaz is offline Offline
Newbie Poster

querry problem

 
0
  #1
Jul 1st, 2009
I'd like to make a querry prom 2 tables that have the same information. Tables have only one column named "fish". I'd like to create a querry that will show me every combination from first table with the second table (in 2 separate columns). For example:
My table contains: A,B,C.
I'd like to get in the querry the following info:
column1 column2
A A
A B
A C
B A
B B
B C
C A
C B
C C

it would be great if in the querry i could eliminate the AA,BB and CC . Thanks in advance
Last edited by sebaz; Jul 1st, 2009 at 11:59 am. Reason: bad title
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,242
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 577
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: querry problem

 
0
  #2
Jul 1st, 2009
  1. IF OBJECT_ID('Table1', 'U') IS NOT NULL DROP TABLE Table1
  2. CREATE TABLE Table1
  3. (
  4. Fish VARCHAR(1)
  5. )
  6.  
  7. IF OBJECT_ID('Table2', 'U') IS NOT NULL DROP TABLE Table2
  8. CREATE TABLE Table2
  9. (
  10. Fish VARCHAR(1)
  11. )
  12.  
  13. GO
  14.  
  15. INSERT INTO Table1 (Fish) VALUES ('A')
  16. INSERT INTO Table1 (Fish) VALUES ('B')
  17. INSERT INTO Table1 (Fish) VALUES ('C')
  18.  
  19. INSERT INTO Table2 (Fish) VALUES ('A')
  20. INSERT INTO Table2 (Fish) VALUES ('B')
  21. INSERT INTO Table2 (Fish) VALUES ('C')
  22.  
  23.  
  24. GO
  25.  
  26. SELECT *
  27. FROM Table1,Table2
  28. ORDER BY Table1.Fish, Table2.Fish

Results:
  1. (1 row(s) affected)
  2. Fish Fish
  3. ---- ----
  4. A A
  5. A B
  6. A C
  7. B A
  8. B B
  9. B C
  10. C A
  11. C B
  12. C C
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC