how can I select all records except where meeting_status.teacher_id not equal to a specific teacher

时间:2018-03-25 20:46:54

标签: php yii phpmyadmin reference

my first table is meeting

id | title | body         | 
---------------------------
1  | mytit | my message   |
---------------------------
2  | anoth | another mes  |
---------------------------
3  | title | again a mess |

my second table is Meeting_status and it has a foreign key from the meeting table and another table called teachers

status_id  |  teacher_id  |  meeting_id 
-------------------------------------------
  1        |   28         |     2         
-------------------------------------------

my query is :

SELECT * FROM meeting LEFT JOIN meeting_status ON meeting.id = meeting_status.meeting_id WHERE meeting_status.teacher_id <> 28

what I want as result is to show only the rows where teacher_id 28 doesn't exist like:

 id  |  title  |   body         | status_id  |  teacher_id  | meeting_id  
 -----------------------------------------------------------------------
 1   |  mytit  |  my message    |  NULL      |   NULL       |  NULL     
 -----------------------------------------------------------------------
 3   |  title  |  again a mess  |  NULL      |   NULL       |  NULL

1 个答案:

答案 0 :(得分:0)

我改变了我的查询:

Gson gson = new Gson();
String json = prefs.getString("MyObject", "");
MyObject obj = gson.fromJson(json, MyObject.class);

它给了我期待的输出。