Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:05:25+00:00 2026-06-10T09:05:25+00:00

From a table like this (this is just for here): p_add | p_add_s |

  • 0

From a table like this (this is just for here):

p_add  | p_add_s | p_phone | p_phone_s | p_user_id //0 = show 1= Hide
Address| 0       | 12345   | 1         | 1
Addr   | 0       | 12345   | 1         | 2

How can I do a select like:

 select p_add (if p_add_s = 0), p_phone (if p_phone_s=0) from table where p_user_id=1
or
    select p_add, p_phone from table where p_user_id=1 (if p_add_s = 0) and (if p_phone_s = 0)

These are incorrect. I included them just so u can get an idea.

Actually I only need data if the value with _s is 0.

Can this be done using sql or it’ll have to achieved using php?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:05:26+00:00Added an answer on June 10, 2026 at 9:05 am

    I think you are looking for the mysql IF syntax:

    select if(p_add_s=0, p_add, 'Address Private'),  if(p_phone_s=0, p_phone, 'Phone Private') from myTable
    

    If the condition is met, it returns the middle section, otherwise, the last one.

    Alternately, based on your second query:

    select p_add, p_phone from table where p_user_id=1 and p_add_s = 0 and p_phone_s = 0
    

    Note that this will not return rows where all the conditions within the where clause are not met, so the if statement might work better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display a table like this Generated from three database tables depends
MY query looks like this: SELECT COUNT(entryID) FROM table WHERE date >= DATE_SUB(CURDATE(), INTERVAL
I like to have a query like this: select data from table where (x
I am trying to do something like this: select char_length(select text_field from table where
I've got a query that looks something like this: SELECT * FROM table WHERE
Is it possible to accomplish something like this using linqtosql? select * from table
I have a select like this: SELECT field1, field2, field3 FROM table WHERE field1=
I have a sql like this: SELECT TOP 1 field_name * FROM table_name and
I found it in a statement like this: delete /*+ restrict_all_ref_cons */ from table_1
I written a query in my sql like this: select * from table_name order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.