Running report from two tables and same column being used multiple times from one of the tables

I had posted a few days ago on this topic, but I am not sure I was very specific. I have two tables I am trying to pull some data from. This is for a report the tables and data I need are this.

Table 1
attribute_ID
attribute_name

Table 2
Attribute_ID
Attribute_name
Attribute Info
Attribute Info
Attribute Info
Attribute Info

The information I am trying to get is all in the attribute info field. Each field has the same attribute ID from table 1. I am going to have to tell it that I need attribute info where it = X and where it = Y and where it = Z and where it = W. My report has the following columns. ID, Name, Job1, Job2, Job3, Job4. I didn't know the best way. Would I do something like this?

SELECT ID, NAME, A.ATTRIBUTE_INFO , B. ATTRIBUTE_INFO, C. ATTRIBUTE_INFO , D. ATTRIBUTE_INFO
FROM TABLE 1, TABLE 2
JOIN TABLE1 ID ON TABLE 2 ID
WHERE A.ATTRIBUTE_INFO=W AND B.ATTRIBUTE_INFO=Y AND C.ATTRIBUTE_INFO=X AND D.ATTRIBUTE_INFO=Z

My report should look like this:

ID Name Job1 Job2 Job3 Job4
1221 Ross X Y Z W

My table looks like this:

ID | Attribute_info | date | time | rim
1221| x | 04/04 | 12 | 9
1221| y | 04/04 | 12 | 9
1221| z | 04/03 | 01 | 3
1221| w | 03/13 | 09 | 1
1221| loading | 02/01| 04 | 9
1221| SQL? | 04/19| 03 | 2

I only need the rows that have x,y z and w. Does this make sense? I tried to explain it a little better

when you run the query you posted, what do you get?

Please post your tables as create table scripts and insert statements with your sample data. You shouldn't make it hard for people to help you, making them have to do these tasks for you and then spend their valuable time helping you trying to guess what it is you want and what you're working with. Also please post the output you want and what you have tried, any errors you got. Armed with this information someone will likely be able to help you. Remember to Google or Bing it first to see if you can learn how to do it yourself.

1 Like