943,739 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 381
  • MS SQL RSS
Jul 1st, 2009
0

querry problem

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sebaz is offline Offline
1 posts
since Jul 2009
Jul 1st, 2009
0

Re: querry problem

sql Syntax (Toggle Plain Text)
  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:
MS SQL Syntax (Toggle Plain Text)
  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
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Table Chaos
Next Thread in MS SQL Forum Timeline: Code inside CATCH not execute





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC