webguy262 Posted December 8, 2010 Share Posted December 8, 2010 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' Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/ Share on other sites More sharing options...
chrisshennan Posted December 8, 2010 Share Posted December 8, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/#findComment-1144632 Share on other sites More sharing options...
webguy262 Posted December 8, 2010 Author Share Posted December 8, 2010 I swear, I'll never grasp the use of ', `," in php & phpmyadmin (in particular)! I need to do some googling! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/#findComment-1144637 Share on other sites More sharing options...
Maq Posted December 8, 2010 Share Posted December 8, 2010 Single quotes are for strings. Backtics are for table names that are the same as reserved words, which you should avoid. Although, they won't hurt even if they're not needed. Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/#findComment-1144643 Share on other sites More sharing options...
chrisshennan Posted December 8, 2010 Share Posted December 8, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/#findComment-1144648 Share on other sites More sharing options...
webguy262 Posted December 9, 2010 Author Share Posted December 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/#findComment-1144743 Share on other sites More sharing options...
chrisshennan Posted December 9, 2010 Share Posted December 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/#findComment-1145084 Share on other sites More sharing options...
webguy262 Posted December 10, 2010 Author Share Posted December 10, 2010 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221061-left-joined-table-all-nulls/#findComment-1145318 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.