Originally posted by xgamen
Hi, I have found something unexpected ..
$query = "select tbl_basic1.HID, neighborhood, lp
from tbl_basic1, tbl_basic2 where tbl_basic1.HID = tbl_basic2.HID and tbl_basic1.HID = 1 OR tbl_basic1.HID = 2";
SELECT t1.HID, t1.neighborhood, t2.lp
FROM tbl_basic1 t1 INNER JOIN tbl_basic2 t2
ON t1.HID = t2.HID
WHERE t1.HID = 1 or t1.HID = 2
You could also use:
WHERE t1.HID IN (1, 2)
Note how I aliased tbl_basic1 to t1 and the same from tbl_basic2. You should also change their names to something descriptive.
Read section 6.1.1 of The Fine Manual, or better yet, an introductory book on database systems. Just the first few chapters of "Introduction to Database Systems" by CJ Date would be very helpful.
You need to learn how to break the problem into steps, rather than just throwing SQL at it and hoping something sticks. That means you really need to learn what joins actually do.
You might also be running into one of SQL's "features": duplicates in your table. Make sure both tables have a primary key, this should probably be HID though I can't tell for certain without knowing your business rules.