getting values by joining tables
Moderator: General Moderators
-
shivam0101
- Forum Contributor
- Posts: 197
- Joined: Sat Jun 09, 2007 12:09 am
getting values by joining tables
Hello,
I have ta table,
id (auto inc), memberid, partnerid, questions
if i want to know questions which are attempted by both, what query should i have to write
for example,
id (auto inc), memberid, partnerid, questions
1 98 99 1
2 98 99 2
3 98 99 1
i should get 1 (since, both attempted question No. 1)
Thanks
I have ta table,
id (auto inc), memberid, partnerid, questions
if i want to know questions which are attempted by both, what query should i have to write
for example,
id (auto inc), memberid, partnerid, questions
1 98 99 1
2 98 99 2
3 98 99 1
i should get 1 (since, both attempted question No. 1)
Thanks
- iknownothing
- Forum Contributor
- Posts: 337
- Joined: Sun Dec 17, 2006 11:53 pm
- Location: Sunshine Coast, Australia
Your question is not very well thought out, or written, it also might help to look at some basic tutorials, but heres a starter...
Code: Select all
SELECT * FROM table_name WHERE question = '1'-
shivam0101
- Forum Contributor
- Posts: 197
- Joined: Sat Jun 09, 2007 12:09 am
- iknownothing
- Forum Contributor
- Posts: 337
- Joined: Sun Dec 17, 2006 11:53 pm
- Location: Sunshine Coast, Australia
Your post is confusing the hell out of me, I kind of get what your trying to say, but my brain is folding in on itself
Could you perhaps redo your table:
to have a bit more uniqueness to it, and then explain which one has what etc, so I can understand. It just seems as though the same numbers are repeating themselves at the moment.
Could you perhaps redo your table:
Code: Select all
1 98 99 1
2 98 99 2
3 98 99 1Code: Select all
Select * from `table` Group By `memberid`,`partnerid`Its still kind of hard to under stand what you want.
I'm reading something different in shivam's question. And note that his subject was about "joining tables". I think he is trying to do something in one table that requires relational tables. I'm guessing that what he really wants is more like this:
tblMembers:
MemberID
MemberName
Question
.... etc.
tblPartners:
PartnerID
PartnerName
Question
.... etc.
Then he could do a Join between the two tables based on having the same value in the Question fields.
But since he hasn't explained what the relationship may be between "members" and "partners", or what these "Questions" are, it is very difficult to know what he is really trying to do. I also wonder whether the Questions field is going to contain just a single number or if he's trying to jam non-atomic values into it.
Shivam, we really do want to help you, but you need to explain what you're doing more precisely.
tblMembers:
MemberID
MemberName
Question
.... etc.
tblPartners:
PartnerID
PartnerName
Question
.... etc.
Then he could do a Join between the two tables based on having the same value in the Question fields.
But since he hasn't explained what the relationship may be between "members" and "partners", or what these "Questions" are, it is very difficult to know what he is really trying to do. I also wonder whether the Questions field is going to contain just a single number or if he's trying to jam non-atomic values into it.
Shivam, we really do want to help you, but you need to explain what you're doing more precisely.
-
shivam0101
- Forum Contributor
- Posts: 197
- Joined: Sat Jun 09, 2007 12:09 am
-
shivam0101
- Forum Contributor
- Posts: 197
- Joined: Sat Jun 09, 2007 12:09 am
I wanted the questions which are attempted by both.
This i solved by using the below query,
Now, i want questions which was not attempted by 96 but attempted by 97
I tried,
This giving me all the questions attempted by 97
i tried intersection, later came to know mysql does not support intersection
This i solved by using the below query,
Code: Select all
select * from table_name WHERE member_id =96 AND member_id =97Now, i want questions which was not attempted by 96 but attempted by 97
I tried,
Code: Select all
select * from table_name WHERE member_id !=96 AND member_id =97i tried intersection, later came to know mysql does not support intersection
-
shivam0101
- Forum Contributor
- Posts: 197
- Joined: Sat Jun 09, 2007 12:09 am