SQL Query Help Needed

Posted on 2014-08-13
Medium Priority
Last Modified: 2014-08-13
I have the following query that pulls the data from a mysql database.

$query="SELECT sid, name, status, task FROM supervision WHERE name = 'employee1' AND active='1'";

Open in new window

The above code works great. I'm trying to add to it but can't figure out how to make it pull all task except any that is listed as work.

How would I edit the query to display all the task except any listed as WORK?
Question by:wantabe2

Accepted Solution

rjohnsonjr earned 2000 total points
ID: 40258291
Like this?

$query="SELECT sid, name, status, task FROM supervision WHERE name = 'employee1' AND active='1' and task!='work'";

Open in new window

LVL 53

Expert Comment

by:Vitor Montalvão
ID: 40258296
How to know if a task is listed as work or not?
LVL 20

Expert Comment

ID: 40258300
You neglect to say if WORK is a value of one of your selected fields or another field...

Assuming WORK is a value of "status" you would add:
AND status <> 'WORK' to your select...

If it is associated with another field, adjust the AND clause as appropriate...
LVL 49

Expert Comment

ID: 40258325

My mind reading license expired, or was it my because crystal ball rolled off the desk....

It really isn't fair to make us volunteers guess how a table only you have access to defines if a task is 'work' or not 'work', the relevant facts should be included in the question - and we will fall over ourselves to provide the correct sql syntax

We really only know a table exists called `supervision` with these fields:
`sid`, `name`, `status`, `task` , `active`

`name` and `active` both appear to hold strings (not sure why `active` would do that)
LVL 49

Expert Comment

ID: 40258326
@rjohnsonjr, you must have renewed that mind reading license :)

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question