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 6705663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:25:48+00:00 2026-05-26T07:25:48+00:00

Query 1: SELECT if(COUNT(0),1,0) as ‘IsPresent’ FROM table1 WHERE Id=1500; Query2: If IsPresent is

  • 0

Query 1:

SELECT if(COUNT(0),1,0) as 'IsPresent'
FROM table1
WHERE Id=1500;    

Query2:

If IsPresent is 1, then

select t2.mark,t2.age from table2  t2,table1 t1
where  t1.ID=t2.ID order by t1.ID;

If IsPresent is 0, then

select mark,age from table2;

ie. if entry is present in a table, i need to join else i don’t need to join.

Is there any way we can achieve this with a single mysql select query?

  • 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-05-26T07:25:49+00:00Added an answer on May 26, 2026 at 7:25 am

    I think you can union the two different query cases which would look like:

    SELECT T2.MARK, T2.AGE
    FROM TABLE1 T1, TABLE2 T2
    WHERE
      T1.ID=T2.ID AND
      T1.ID=1500
    UNION
    SELECT MARK, AGE
    FROM TABLE1
    WHERE
      NOT ID=1500
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my query: SELECT (SELECT COUNT(`id`) FROM `table1` WHERE `id` = '1') AS `count1`,
I have this query: select count(id) AS num,date_id from table where FROM_UNIXTIME(date_id,'%d-%m-%Y')='17-08-2009' order by
I have the following query SELECT Count(*) as Total_Count, Col1 FROM Table1 GROUP BY
So, I have this query: SELECT count(*) AS count FROM table1 INNER JOIN some
In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
When I run the query : select count(*) from (select idCover from x90..dimCover group
I have the following query: SELECT COUNT(*) FROM FirstTable ft INNER JOIN SecondTable st
I have this query: SELECT COUNT(articles.id) AS count FROM articles, xml_documents, streams WHERE articles.xml_document_id
Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
If I run a query such as: SELECT COUNT(*) as num FROM table WHERE

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.