BigJobbies
BigJobbies

Reputation: 4343

MySQL - Query not outputting the right response

I have a table with friend1, friend2 and request, basically the end of the statement im trying to only output rows where the request is equal to p ... But it seems to be giving me an error instead.

My query is as follows:

SELECT * FROM friends WHERE friendfrom=8 OR friendto=8 AND request=p

The error message im getting is as follows:

Unknown column 'p' in 'where clause'

Can anyone please give me a bit of help ... Im quite stumped on this.

Upvotes: 0

Views: 50

Answers (3)

Bajrang
Bajrang

Reputation: 8629

If you dont write a string into single or double quote then it will treated as a column name of your table. that's why you have above error. so replace your query with this one:=

SELECT * FROM friends WHERE friendfrom=8 OR friendto=8 AND request='p';

Upvotes: 0

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230461

Is p a string? You probably want this:

SELECT * FROM friends WHERE friendfrom=8 OR friendto=8 AND request='p';

Upvotes: 0

Adam Wenger
Adam Wenger

Reputation: 17560

p is a literal, you need to use ' marks to show that:

SELECT *
FROM friends
WHERE friendfrom = 8
   OR friendto = 8
   AND request = 'p'

Upvotes: 2

Related Questions