Jump to content

SQL Error


johnrb87

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/210074-sql-error/
Share on other sites

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
";
?>

Link to comment
https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096360
Share on other sites

<?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 :)

Link to comment
https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096393
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/210074-sql-error/#findComment-1096396
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.