Jump to content

Weird query


tibberous

Recommended Posts

I have a table called users, with three fields, firstname, lastname and displayname.

 

If displayname isn't null, I want to select displayname, otherwise I want to select firstname, a space, and then lastname. I'm guessing I'll need to use concat, but I'm not sure how to do the actually decision part.

Link to comment
Share on other sites

Couldn't you just do the decision making in php?

 

if($display_name <> "")
{
    $query = "Select * FROM users WHERE displayname = ".$display_name.";";
}
else
{
    $query = "Select * FROM users WHERE displayname = ".".$firstname." ".$lastname.";";
}

No because the displayname and the firstname/lastname are stored in separate fields within the users table. What the OP wants to do is return the firstname and lastname as the displayname if the displayname is not set within the users table, or just the displayname if it is set. My query does this.

Link to comment
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.