Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.