Emma
Emma

Reputation: 3

SQL query having an issue

Hi there I'm having an issue with an SQL query, it works but I don't know if it's right (I'm learning to code)..

I've written this statement..

SELECT CONCAT(Member_Name, ' ', last_name) AS full_name FROM members ORDER BY last_name DESC, Member_Name DESC

It's displaying this:

enter image description here

Is this right? Thanks!

Upvotes: 0

Views: 54

Answers (2)

Ayush Ghosh
Ayush Ghosh

Reputation: 487

Your query is absolutely correct. You need the data order by lastname, so however you may structure the query it will be same output.

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269483

Too long for a comment.

Your query looks right. Just ignore "Tony House" and the results look correct too ;) Sometimes, situations like this arise because the data isn't what you think it is. I would suggest that you run the query with the basic data in other columns so you can see what is happening:

SELECT CONCAT(Member_Name, ' ', last_name) AS full_name, Member_Name, last_name
FROM members
ORDER BY last_name DESC, Member_Name DESC;

You are likely to find an anomaly in the data. For instance, "Tony House" might be in the Member_Name field and the last_name field is blank. Or, there might be an extra space or unprintable character in the last_name field.

Upvotes: 1

Related Questions