0

I am having table x.

x
............
id    email      first_name   last_name
'''''''''''''''''''''''''''''''''''''''
 1  [email protected]  Martin        Robert
 2  [email protected]     
 3  [email protected]  Sam           Anderson

I am using following query and the output is:

 select id, CONCAT(first_name, ' ', last_name) from a;

 The output is
 .......................................
 id    CONCAT(first_name, ' ', last_name)
 '''''''''''''''''''''''''''''''''''''''
  1    Martin Robert
  2
  3    Sam Anderson     

I Want to ignore the row which has both first_name and last_name is empty in CONCAT().

My output will be as follows

  .......................................
 id    CONCAT(first_name, ' ', last_name)
 '''''''''''''''''''''''''''''''''''''''
  1    Martin Robert
  3    Sam Anderson 

Thanks in advance.

1
  • Then you need a WHERE clause in your query Commented Feb 21, 2019 at 9:56

4 Answers 4

1

This way:

select id, CONCAT(first_name, ' ', last_name) from a where first_name is not null and last_name is not null;
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT ID, CONCAT(FIRST_NAME, ' ', LAST_NAME)
FROM TABLE_NAME_A
WHERE FIRST_NAME IS NOT NULL
AND LAST_NAME IS NOT

1 Comment

While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanation, and give an indication of what limitations and assumptions apply.
1

You need where clause

assuming the empty value mean null value

 select id, CONCAT(first_name, ' ', last_name) 
 from a 
 where first_name is NOT null 
 and last_name is NOT null;

or for test also empty string

 select id, CONCAT(first_name, ' ', last_name) 
 from a 
 where ifnull(first_name,'') = '' 
 and ifnull(last_name,'') =  '';

3 Comments

Might need to add a and first_name != '' as that may not actually be null :)
What is the difference this this from the answer below?
@VijunavVastivch the first just check if the value is not assigned (NULL) the second check if the value is not assigned or the value in as empty string (null or '')
1

Try this, it should must work in your case:

SELECT id, CONCAT(first_name, ' ', last_name) as fullname 
FROM YOUR_TABLE_NAME 
WHERE first_name != "" AND last_name != "";

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.