I have a previous query in which I return certain student_id numbers in an array called $student_id. This array could contain 10 to 30 values in it.

I would then like to query a different table so that I can return the student info based on the values in the $student_id array. The values in $student_id are related to the field ID in the student_main table.

$query_student_display = sprintf("SELECT * FROM student_main WHERE ID ... ");

"..." would be the info from my $student_id array.

Any ideas?

    i think you could just do a query like,

    SELECT FROM table WHERE id IN (SELECT FROM other_table WHERE ... )

      Coldwerturkey,
      This is the error message I get when I tried your suggestion:
      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 'SELECT * class_list WHERE Class = 'English12')' at line 1

      Here is the actual code

      $query_student_display = "SELECT * FROM student_main WHERE ID IN (SELECT * class_list WHERE Class = 'English12')";

      FWIW MySQL client version is 4.0.18.

      Edit:
      I actually want the student_main.ID to compare class_list.Stud_ID where the class = 'English12' (or whatever class I want to query)
      So the field names in the two tables are different.

        I got it! Here's what I came up with:

        $query_student_display  = ("SELECT * FROM student_main, class_list WHERE class_list.Class = 'English12' AND student_main.ID = class_list.Stud_ID");

        I will mark this as resolved. Thanks for the help!

          Write a Reply...