1

I have been trying to find the correct query for this problem but it doesn't quite work so I'm asking here:

I have 2 tables:

Table-1 has 5 rows with 6 attributes each

Table-2 has 3 rows with 5 attributes and EACH attribute corresponds to 1 row from table 1. What I want is a query that will give me all the attributes from table 1 that are contained in table 2. I've come up to this:

SELECT *
FROM Table1
WHERE PrimKey IN
   (SELECT *
    FROM Table2
    WHERE PrimKey = Index)

However it won't let me do this because it says that on the second SELECT I can't select all but I have to choose. This way I can only view 1 row of Table1 stuff from Table2 but I want to view all of Table2's attributes.

3
  • The error that you are seeing is because you have more than one field in Table2 and you are using 'SELECT *' in your subquery Commented Nov 29, 2013 at 19:24
  • Assuming Muhammed's answer doesn't solve your problem you are going to have to give us some more information. Show us the schema of Table1 and Table2. Commented Nov 29, 2013 at 21:23
  • Muhammed's answer isn't what I'm looking for. Table 1 schema: PrimKey, Attribute1, Attribute2, Attribute3 Table 2: PrimKey, Attribute1, Attribute2, Attribute3, Attribute4 where those attributes have as values the PrimKey of Table 1. Table 1 is a list of clothes with attributes: color, size etc. Table 2 is a list of cloth combinations and attributes here are any of the T-1 tuple rows. For example the first row of T2 has as Attr-1:Shirt (the PrimKey of the "Shirt" tuple in table 1), Attr-2:Pants etc. What I want is by knowing the table 2 PrimKey to get as the result the tuples from table 1. Commented Nov 30, 2013 at 0:32

1 Answer 1

1
SELECT *
FROM Table1
WHERE PrimKey IN
   (SELECT PrimKey 
    FROM Table2)

Or INNER JOIN

SELECT t1.* 
FROM Table1 t1 INNER JOIN Table2 t2
ON t1.ReferencingColumn = t2.ReferencingColumn
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.