Round Posted November 14, 2006 Share Posted November 14, 2006 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 ThanksP.S Its an mssql db. Quote Link to comment https://forums.phpfreaks.com/topic/27207-join-queries/ Share on other sites More sharing options...
MCP Posted November 15, 2006 Share Posted November 15, 2006 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.. Quote Link to comment https://forums.phpfreaks.com/topic/27207-join-queries/#findComment-124783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.