0

I don't know how to create a Formula for It, but i have a table user. Schedule_ID (which are all array values). i want to get all IDs in schedule table that match the value in Schedule_ID.

it's like Where Schedule_ID(Any Value in Array(1,2,3)) = schedule.ID;

for now this is what i've got:

$sql="SELECT schedule.*,user.* FROM user
LEFT JOIN schedule ON user.Schedule_ID = schedule.ID
WHERE user.Schedule_ID = schedule.ID";
4
  • what database are you using? Commented Aug 12, 2018 at 3:52
  • @DamianSimonPeter im using php and mysql Commented Aug 12, 2018 at 3:54
  • I left an answer for you let me know how if that solution worked for you. Commented Aug 12, 2018 at 4:09
  • @Jun what is your expectation and what undesirable output are you getting? Commented Aug 12, 2018 at 4:37

2 Answers 2

1

If I understand your question correctly, I think this query will do what you want:

SELECT schedule.*, user.* FROM user
LEFT JOIN schedule ON FIND_IN_SET(schedule.ID, user.Schedule_ID)

Note this query assumes the Schedule_ID field in user is of the form '1,2,3' or '6,8' etc.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi Nick, i tried your solution, it's not working.. There's already a Value for Schedule_ID which is (1,2,3) i need to Output schedule.ID which match the Schedule_ID. But thank you for answering
Does the value include the left and right brackets? i.e. it is a string '(1,2,3)'
Nope. i.e User 1 have Schedule_ID = 1,2,3. those 1,2,3 are Schedule.ID values in schedule table. Now i want to Output Schedules for User1 that match schedule.ID in user.Schedule_ID. So if there are many Schedules in schedule table only those schedule.ID = 1,2,3 will be displayed.
Thanks! This solve the Problem. Thank you! It's working now
Great. Glad to be of help.
0

The SQL IN operator can help you out here, you may need to modify my answer depending on your setup but this should help you solve the problem or give you an idea.

SELECT schedule.ID
FROM schedule
LEFT JOIN schedule 
ON user.Schedule_ID = schedule.ID
WHERE schedule.ID IN (user.Schedule_ID)

1 Comment

hi @damian, i tried your solution but it's not working

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.