Jump to content

help with join


ifm1989

Recommended Posts

I know little about the join function of mysql, and the official manual just confuses me- I dont know what kind of join to use.

 

 

I have table 1. For simplicity, lets say the columns are:

Bonus ID | Bonus Name

 

 

I have table 2. For simplicity, lets say the columns are:

User ID | Bonus ID

 

 

I need two queries:

 

1) Pulls all of the data in table1. If it finds a matching row in table 2, then the corresponding row in bonus gets set to true. If not, then set to false.

 

2) Pulls ONLY the data in table1 IF it finds a matching row in table 2. Then, the corresponding row in bonus gets set to true. If not, then set to false.

 

 

 

Sample:

 

Table1

1 Pie

2 Foo

3 bar

 

Table 2

1 1

1 2

2 1

 

 

For method 1, if userid = 1, then:

1 Pie true

2 Foo true

3 bar false

 

For method 2, if userid = 1, then:

1 Pie true

2 Foo true

 

 

I hope I'm making this easy to understand. My english isnt very good, and my skill with mysql is worse :/

Link to comment
Share on other sites

I don't understand the need for the 2 queries. The outcome is the same in both - something (undefined) gets set true or false. In the second, if it only pulls matching records, how do you hope to update those not matched, as they are excluded?

 

Also you call them "table1" and "table2" for the sake of simplicity, yet you say a (undefined) column in "bonus" gets set to true or false. So is the "bonus"  table "table1" or "table2", or something you haven't even mentioned?

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.