Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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