Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. MySQL
  4. Boolean query result

Boolean query result

Scheduled Pinned Locked Moved MySQL
databasequestion
3 Posts 3 Posters 31 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Ger Hayden
    wrote on last edited by
    #1

    I am querying a table to see if a person ID exists on the table using e.g. : select IF(Count(*),0,1) from transactionlog where person_id = 1 What I want is something that returns a boolean true or false e.g. select TRUE from transactionlog where person_id = 1. Does such a feature exist? GER

    Ger

    D M 2 Replies Last reply
    0
    • G Ger Hayden

      I am querying a table to see if a person ID exists on the table using e.g. : select IF(Count(*),0,1) from transactionlog where person_id = 1 What I want is something that returns a boolean true or false e.g. select TRUE from transactionlog where person_id = 1. Does such a feature exist? GER

      Ger

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      You might try the following, but remember that TRUE and FALSE are equal to 1 and 0 in MySQL:

      SELECT IFNULL(COUNT(*)>0,0) FROM transactionlog WHERE person_id=1;

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      1 Reply Last reply
      0
      • G Ger Hayden

        I am querying a table to see if a person ID exists on the table using e.g. : select IF(Count(*),0,1) from transactionlog where person_id = 1 What I want is something that returns a boolean true or false e.g. select TRUE from transactionlog where person_id = 1. Does such a feature exist? GER

        Ger

        M Offline
        M Offline
        moxwose
        wrote on last edited by
        #3

        select (case when count(*) >=1 then 1 else 0 end) as existance from [yourtablename] where conditions;

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups