We help IT Professionals succeed at work.

How to query using derived table and multi CTEs...

Mike Eghtebas
on
532 Views
Last Modified: 2015-06-30
Having temp table #t contain:
Product  ProdType
A            x
B            x
B            xx
C            x
D            x
D            xx
E            x

Question: Using derived table and also CTEs (2nd solution), How to produce result like:
ProdType  ProdType
B            x
B            xx
D            x
D            xx

These solutions basically ignore products with single ProdType?

T-SQL to build #t:
create table #t(Product char(1), ProdType varchar(2));
Insert into #t(Product, ProdType) Values
('A', 'x')
, ('B', 'x')
, ('B', 'xx')
, ('C', 'x')
, ('D', 'x')
, ('D', 'xx')
, ('E', 'x');

Select * From #t;

Open in new window

Comment
Watch Question

Database and Application Developer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Mike EghtebasDatabase and Application Developer

Author

Commented:
Note to experts, This question was added to be referenced by an article to build temp table #t.

Thanks.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.