Jump to content

left joined table all nulls?


webguy262

Recommended Posts

I'm trying to do a simple left join of two table on a common column.

 

For some reason, the joined table values are all coming back NULL.

 

What am I missing?

 

SELECT *

FROM surveyview_staging

LEFT JOIN surveyallanswers_staging ON 'surveyallanswers_staging.response_id' = 'surveyview_staging.response_id'

Link to comment
Share on other sites

Hi,

 

It wouldn't be because you've got apostrophes around the fields in the ON part of the query would it?

 

Try the following and let me know how you get on.

 

SELECT *

FROM surveyview_staging

LEFT JOIN surveyallanswers_staging ON surveyallanswers_staging.response_id = surveyview_staging.response_id

Link to comment
Share on other sites

The basic rules I use with ', ` and " are:-

 

I only use ` in MySQL and only where the field is a reserved word i.e. you have a field called date so the query ends up like

 

SELECT title, `date` FROM sometable

 

I use ' and " within PHP for different things:

 

if we have a variable called $test with a value of "this is my sample data";

 

' spits out exactly what's within the apostrophes (variable aren't evaluated) so

 

echo 'My text is: $test'; will output

My text is: $test

 

" allows the variables to be evaluated so

 

echo "My text is: $test"; will output

My text is: this is my sample data

 

I hope this helps

Link to comment
Share on other sites

Chris / Maq

 

Thanks for the guidance! Very clear!

 

One question...  Is there a difference between $var['foobar'] and $var[foobar]?

 

I recall having to use one or the other but I'm not clear on the difference.

 

Hard to goog this kind of stuff b/c the punctuation gets ignored.

Link to comment
Share on other sites

Hi,

 

To use associative arrays you would use $var['foobar'] however $var[foobar] would result in a "use of undefined constant" unless you had specifically declared foobar as a constant.

 

Typically you have to use quotes or apostrophes around associative array keys

 

i.e. $var['foobar']

 

and numeric based keys don't have the quotes / apostrophe.

 

i.e. $var[0]

 

I hope this helps

Link to comment
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.