N
N
nikita_arut2014-11-30 21:02:52
PHP
nikita_arut, 2014-11-30 21:02:52

How is it possible to implement such a sql select?

Hello,
I experienced difficulty in building the right query, your help is really needed.
There are 2 tables - schedule and hw_10.
Actually, you need to display the hw column from hw_10,
while checking for compliance with
hw_10.subject_id = schedule.`first`,
schedule.student_id=1 (variable from php) and
hw_10.`date`='2014-11-24' (also php variable previously selected from the database)...
That's how tricky it is. So far, it has been possible to compose only on 1 subject_id

SELECT 
     hw_10.hw as hw
         FROM schedule
         LEFT JOIN hw_10 ON hw_10.subject_id = schedule.`first`
     WHERE schedule.student_id = '1' 
     AND schedule.day = 'Monday' 
     AND hw_10.`date` = '2014-11-24'

Schedule table:
3e5f164eb42348219d48a4003fb44a0e.png
hw_10 table:
896d3e3744c243bc9c1249b203a47cbe.png
I would be very grateful!
...
Let me explain: you also need to get LEFT JOIN hw_10 ON hw_10.subject_id = schedule.`second`, etc., up to tenth

Answer the question

In order to leave comments, you need to log in

3 answer(s)
_
_ _, 2014-11-30
@AMar4enko

LEFT JOIN hw_10 ON hw_10.subject_id IN [schedule.`first`, schedule.`second`, schedule.`third`, schedule.`fourth`, ...]

N
nikita_arut, 2014-11-30
@nikita_arut

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[schedule.`first`, schedule.`second`, schedule.`third`, schedule.`fourth`] ' at line
4 made wrong...

SELECT 
     hw_10.hw as hw
         FROM schedule
         LEFT JOIN hw_10 ON hw_10.subject_id IN [schedule.`first`, schedule.`second`, schedule.`third`, schedule.`fourth`]
     WHERE schedule.student_id = '1' 
     AND schedule.day = 'Monday' 
     AND hw_10.`date` = '2014-11-24'

M
Mykola, 2014-11-30
@iSensetivity

...........

LEFT JOIN hw_10 ON hw_10.subject_id IN (schedule.`first`, schedule.`second`, schedule.`third`, schedule.`fourth`)

Round brackets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question