Left Join Problems

I have two tables. One contains languages and the other contains user’s 
language skills. I need a query that will return all languages and the language 
skills for specified user. Language skills for other languages not associated 
to the user are null.

The query below returns all languages not used in the user_languages table and 
the language and language skills associated to specified user_id. Problem is 
that the result does not include the languages associated with other user_ids 
in the user_languages table.

[using MySQL 5]

SELECT 
  la.Language_name
  , la.Language_id
  , ul.user_id
  , ul.LanguageSpeak
  , ul.LanguageWrite
  , ul.LanguageRead
FROM 
  Languages la  LEFT JOIN  user_languages ul ON  la.Language_id = ul.Language_id
WHERE
  ((ul.User_id is null) OR (ul.User_id = 1));


‘languages’ Table
------------------------------
| Language_id | LanguageName |
==============================
|      1      |  English     |
------------------------------
|      2      |  Spanish     |
------------------------------
|      3      |  French      |
------------------------------


‘user_languages’ Table
------------------------------------------------------------------------
| user_id | language_id | languageRead | languageSpeak | languageWrite |
========================================================================
|    1    |      1      |      1       |      1        |      1        |
------------------------------------------------------------------------
|    1    |      2      |      0       |      1        |      0        |
------------------------------------------------------------------------
|    2    |      3      |      1       |      1        |      1        |
------------------------------------------------------------------------

query result for user_id = ‘1’
-----------------------------------
| Language | Read | Speak | Write |
===================================
| English  |  x   |   x   |   x   |
-----------------------------------
| Spanish  |      |   x   |       |
-----------------------------------

Problem is language_id #3 (French) is not included in the result.

Any suggestions or ideas?

DougF

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create Web Applications With ColdFusion MX7 & Flex 2. 
Build powerful, scalable RIAs. Free Trial
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJS 

Archive: http://www.houseoffusion.com/groups/SQL/message.cfm/messageid:2799
Subscription: http://www.houseoffusion.com/groups/SQL/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.6

Reply via email to