johnrb87 Posted August 7, 2010 Share Posted August 7, 2010 Good day all I have the following code SELECT items.id, items.title, items.price, (SELECT value FROM new WHERE id = items.id) AS value1 FROM myitems items JOIN people p ON p.person_id = items.id WHERE items.active = 1 AND ((items.title LIKE '%apple%') || (value1 LIKE '%apple%')) ORDER BY items.id ASC but I keep getting #1054 - Unknown column 'value1' in 'where clause' But i'm not sure why this is happening, as value1 exists Can anyone help? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/ Share on other sites More sharing options...
sinista Posted August 7, 2010 Share Posted August 7, 2010 not to sure if it will work, but how about this? <?php $sql=" SELECT items.id, items.title, items.price, v.value as value1 FROM (SELECT value FROM new WHERE id = items.id) v, myitems items JOIN people p ON p.person_id = items.id WHERE items.active = 1 AND ((items.title LIKE '%apple%') || (v.value LIKE '%apple%')) ORDER BY items.id ASC "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096360 Share on other sites More sharing options...
johnrb87 Posted August 7, 2010 Author Share Posted August 7, 2010 Thanks, but that didn't seem to do the job, any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096368 Share on other sites More sharing options...
sinista Posted August 7, 2010 Share Posted August 7, 2010 did you get the same error or something completely different? Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096369 Share on other sites More sharing options...
johnrb87 Posted August 7, 2010 Author Share Posted August 7, 2010 seems to be the same error Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096371 Share on other sites More sharing options...
johnrb87 Posted August 7, 2010 Author Share Posted August 7, 2010 I guess the issue is with AS value1 linking into value1 LIKE '%apple%' does something just need to be edited with those bits of the query? Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096392 Share on other sites More sharing options...
sinista Posted August 7, 2010 Share Posted August 7, 2010 <?php $sql=" SELECT items.id, items.title, items.price, v.value FROM (SELECT value FROM new WHERE id = items.id) v, myitems items JOIN people p ON p.person_id = items.id WHERE items.active = 1 AND ((items.title LIKE '%apple%') || (v.value LIKE '%apple%')) ORDER BY items.id ASC "; ?> dunno really its hard to debug SQL, without a database Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096393 Share on other sites More sharing options...
sinista Posted August 7, 2010 Share Posted August 7, 2010 <?php $sql=" SELECT items.id, items.title, items.price, v.value FROM (SELECT value FROM new WHERE id = items.id) v, myitems items JOIN people p ON p.person_id = items.id WHERE items.active = 1 AND ((items.title LIKE '%apple%') || (v.value LIKE '%apple%')) ORDER BY items.id ASC "; ?> dunno really its hard to debug SQL, without a database I know i wrote the quoted code but if it was me i think i would look at WHERE id = items.id) i would try replacing the item_id for an actual value, then i would take the OR out then see if it works, you just gotta play with SQL sometimes Quote Link to comment https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096396 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.