Jump to content

Join Queries??


Round

Recommended Posts

I am trying to join to queries and what I thought should work isn't.

$sql = "select stu_id, aos_code from table where stu_id in (select distinct stu_id from table where issues = null )";

I want it to display all the students ID numbers and their course code if they haven't got any issues stored against them in the studetails table.

If I just run query:

$sql = "select distinct stu_id from table where issues = null ";

It displays all the student ID's that do not have any issues stored, but I want to join it to the other table to retrieve their course code aswell. Its an mssql db.

I've even tried:

$sql = "select stu_id, aos_code from table where stu_id [color=red]=[/color] (select distinct stu_id from table where issues = null )";

Many Thanks

P.S Its an mssql db.
Link to comment
https://forums.phpfreaks.com/topic/27207-join-queries/
Share on other sites

Hello Round,

try

[code]select stu_id, aos_code from stmaos where stu_id in (select stu_id from studetails where issues is null)[/code]

null is special in that you use [i]issues is null[/i] or [i]issues is not null[/i] instead of the regular operator.

i'm kind of surprised that [i]= null[/i] worked, but that might have something to do with db settings and such..

also, when using "in" you don't need to specify "distinct", as you might with a join. all the statement will check to see if the value is present. a distinct (i think) might cause it to actually figure out the distinct values, and then check. Not sure, but definitely not needed..
Link to comment
https://forums.phpfreaks.com/topic/27207-join-queries/#findComment-124783
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.