Ibnu Agiels Althur Ibnu Agiels Althur - 1 year ago 126
SQL Question

SELECT WHERE id = 1 but returned id = 11?

I have 2 tables; let's just call them foo_table and bar_table.

So, foo_table's id is a foreign key for bar_table.

And in bar_table there is foo_table's id = 11

BUT, when I tried:

SELECT * FROM bar_table AS b
INNER JOIN foo_table AS f ON b.foo_id = f.foo_id
WHERE b.foo_id = 1

It should return NULL because there isn't any data in bar_table with foo_id = 1 but it returns data with foo_id = 11

Can anybody fix it?


Sorry I didn't write my table...

Here's the sqlfiddle

Answer Source

Always group boolean operations. This will make certain that they are interpreted in the manner you desire.

WHERE k.id_pegawai = '1'
  AND (k.status_keluarga = 'suami' OR k.status_keluarga = 'istri')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download