0

In my query I want to check if the users with the specified permissions exists or not. Presently I am using the below query. It will retrieve the rows of authorised users with the specified conditions.

select a.ixUserAuthorization from tblechecklistuserroleassignmentxref r
inner join tblechecklistuserrole u on u.ixUserRole=r.ixUserRole and u.sname='Initiator'
inner join tblechecklistuserauthorization a on a.ixUserAuthorization=r.ixUserAuthorization
and a.ixcustomer='1'and a.ixprogram='1'and a.ixworkpackage='1'and a.ixactivity='1' and a.ixUser='626e28e8-e67a-4d11-8d2c-129d0ab79e96';

If any rows are returned i want to display the result as true ,If no rows are returned from the above query I want to display the result as false.

How can I modify to obtain the result as true or false .

2
  • Whether count() can be used? how to count the no of rows of select query result ? Commented May 28, 2012 at 7:10
  • 1
    using function mysql_num_rows() on your result Commented May 28, 2012 at 7:15

2 Answers 2

1
SELECT CASE 
         WHEN Count(*) >= 1 THEN 'true' 
         ELSE 'false' 
       END AS Answer 
FROM   (SELECT a.ixUserAuthorization 
        FROM   tblechecklistuserroleassignmentxref r 
               INNER JOIN tblechecklistuserrole u 
                 ON u.ixUserRole = r.ixUserRole 
                    AND u.sname = 'Initiator' 
               INNER JOIN tblechecklistuserauthorization a 
                 ON a.ixUserAuthorization = r.ixUserAuthorization 
                    AND a.ixcustomer = '1' 
                    AND a.ixprogram = '1' 
                    AND a.ixworkpackage = '1' 
                    AND a.ixactivity = '1' 
                    AND a.ixUser = '626e28e8-e67a-4d11-8d2c-129d0ab79e96') a 
Sign up to request clarification or add additional context in comments.

2 Comments

I got the requied result .. just for information Can you explain why 'a' is needed at end .
Every Inner Sql need to give an alias to make it part of outer From Statement.
1

use function mysql_num_rows

ex:

if(mysql_num_rows($result))
  echo "true";
else
   echo "false";

where $result is the result of your query

1 Comment

How do you know if php is being used?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.