1

i have a select query in my php file as next >>

$sql = 'SELECT * 
    FROM notes
    WHERE notes.code_apogee='.$CA.'';

that return some empty rows where i should set a default value << 'en attend'

i used IFNULL as below :

SELECT IFNULL( (SELECT *
    FROM notes
    WHERE notes.code_apogee='.$CA') ,'en attend');

but an error appear

 MySQL a répondu: Documentation
#1241 - Operand should contain 1 column(s)

any help ?? please

3
  • 1
    How do you define "empty rows"? A specific column, or all the columns in a specific row? Can you give an example with your dataset? Commented Jun 5, 2017 at 23:41
  • in notes table i have a group of columns where code_apogee is one of them and i use it as condition at this case, some of rows return a blank field so wanna to put in a default value ? Commented Jun 5, 2017 at 23:48
  • I think (not sure): the function IFNULL only takes one single column/value as param. You give it several (as many as all the columns in table notes) Commented Jun 5, 2017 at 23:50

1 Answer 1

3

IFNULL() won't take a subselect (which is all the columns in your case) as param, but just one (plus the else value).
So your query should be something like this:

SELECT id, 
    IFNULL(notes.title, 'en attend') as title, 
    IFNULL(notes.body, 'en attend') as body 
FROM notes
WHERE notes.code_apogee='.$CA'

(I just invented notes.title & notes.body, you need to replace that with actual column names)

You could of course let the db just return the NULLs and add 'en attend' when displaying the results:

echo !is_null($row['title']) ? $row['title'] : 'en attend';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.