Jump to content

Hi stuck at this any way around?


takn25

Recommended Posts

I have a table called data which stores name and other material and there is a table called

match.

 

Match has an auto incrementing id called match_id and a row called match_1 and match_2.

 

Ok what happens is an id which is unique from the data table is stored in match_1 and another

id which is unique from the data table is stored in match_2

 

For example

 

Match_id    match_1    match_2

40            1          2

 

40            2          1

 

Is there any way to retrive the data of both ids for instance in this case match_1 and match_2

based on the match_id being same? I tried a few joining queries but no luck for me could some one tell me how can I achieve this thanks.

 

Basically get name place etc details of match 1 and match 2  based on the match_id

Link to comment
Share on other sites

The thing is there is a name row in the data table and a place so if I do a while loop for fetching data

 

I dont understand how will I tell SQL that I want to fetch data of the match_1 and also match_2

I am able to fetch data of one of these not both with a join query but I dont know how can I fetch data

of both match_1 and match_2 in a single query is this possible?

 

For instance While ($row =mysql_fetch_assoc($result))

{

$name = $row['name'];

 

echo $name

}

 

If I echo $name it just shows either match_1 or match_2 and their data not both of them I dont know if I am making any sense could some one guide me thanks alot!

 

Link to comment
Share on other sites

I don't have any experience with JOINs or even subqueries, but this seems to work on my test database:

SELECT * FROM data WHERE match_id = ANY(SELECT match_1 FROM match WHERE match_id=40) OR match_id = ANY(SELECT match_2 FROM match WHERE match_id=40)

Link to comment
Share on other sites

Thanks dcro for trying to help but its a weird case what I am trying to achieve I want to select both of the

 

 

match_1 and match_2 data at the same time rather than using OR and selecting only one of these I guess its not possible but thanks for the help!

Link to comment
Share on other sites

That is what my query is supposed to do.. I tested it with two rows with the same match_id and it returned the data from the data table for all the different match ids. OR just means it'll return rows that match either condition. I don't know the field names of your data table, so I just used match_id.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.