i have two tables
CREATE TABLE IF NOT EXISTS `user` ( `user_id` int(20) NOT NULL AUTO_INCREMENT, `ud_id` varchar(50) NOT NULL, `name` text NOT NULL, `password` text NOT NULL, `email` varchar(200) NOT NULL, `image` varchar(150) NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB
and mycatch table is
CREATE TABLE IF NOT EXISTS `mycatch` ( `catch_id` int(11) NOT NULL AUTO_INCREMENT, `catch_name` text NOT NULL, `catch_details` text NOT NULL, `longitude` float(10,6) NOT NULL, `latitude` float(10,6) NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `image` varchar(150) NOT NULL, `user_id` int(20) NOT NULL, PRIMARY KEY (`catch_id`), KEY `user_id` (`user_id`) ) ENGINE=InnoDB; ALTER TABLE `mycatch` ADD CONSTRAINT `mycatch_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
i want to retrieve data from both the tables. i.e
SELECT longitude,latitude FROM user u LEFT JOIN mycatch m ON u.user_id = m.user_id WHERE u.ud_id =de15a674d1252f6565a65756ebfa97e8e1e58c9c AND m.catch_id >7
but this give me error #1054 - Unknown column 'de15a674d1252f6565a65756ebfa97e8e1e58c9c' in 'where clause'
but when i change u.ud_id=123456789 then it works fine
you need single quotes around the u.ud_id
SELECT longitude,latitude
FROM user u
LEFT JOIN mycatch m ON u.user_id = m.user_id
WHERE u.ud_id = 'de15a674d1252f6565a65756ebfa97e8e1e58c9c'
AND m.catch_id >7