need help with joining tables SQL / PHP

Discussion in 'Programming' started by matt_62, Jun 11, 2012.

  1. #1
    having trouble joining tables in sql. All its supposed to do is find all records where a number is < a specific value

    here is what i tried:
    select stu_name, student_number, description FROM student, enrolment, subject where student.student_number = enrolment.student_number
    AND enrolment.subject_number = subject.subject_number
    AND grade < 50;

    (im aware of the typo of enrollment, however the spelling of all tables / databases actually matches what ive set up so its not that.)

    Ive tried looking it up and ive got text books, but im stumped. Can anyone tell me the correct syntax for joining 3 tables and filtering all records based on 'tablename < value'


    personally if i wanted to join tables, i would have become a carpenter.
     
    matt_62, Jun 11, 2012 IP
  2. dollarfish

    dollarfish Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #2
    You should use aliases ie
    select sub.stu_name, st.student_number FROM student as st, enrolment as enr, subject as sub where st.student_number = enr.student_number
    AND enr.subject_number = sub .subject_number

    Other opttion is to use INNER JOIN ON but you need to google it
     
    dollarfish, Jun 12, 2012 IP