Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing multiple columns in mySQL
    text
    copied!<p>I need to compare two different columns in a mysql <code>WHERE</code> statement. Within a view that I have created I have a column called <code>E_ID</code> and one called <code>event</code>. I need to <code>SELECT</code> from the view where the <code>E_ID</code> != <code>$E_ID</code> when <code>event</code> = <code>$event</code>.</p> <p>So if <code>$event</code> = status and <code>$E_ID</code> = 1 the statement would select anything thats not got the same event and the same <code>E_ID</code> but it could return data that has the same <code>E_ID</code> and a different event. </p> <p>Okay lets have some examples. Lets say I have this as my two variable:</p> <pre><code>$E_ID = '1'; $event = 'status'; </code></pre> <p>Okay and now in the table is this;</p> <pre><code>E_ID event 1 status 2 status 3 status 1 gig 3 track 5 gig </code></pre> <p>As you cans the first row contains the data set in the variables so we don't want to return that. But the problem lies in <code>E_ID</code> as they can be the same if the event is different. So I want to return everything that does not have the <code>E_ID</code> of <code>1</code> when the <code>event</code> is <code>status</code>. It can however return data of the same E_ID and the same event.</p> <p>What should be returned is this;</p> <pre><code>E_ID event 2 status 3 status 1 gig 3 track 5 gig </code></pre> <p>As you can see everything is returned but the row that has the data set in the variables.</p> <p>Here's my query so far.</p> <pre><code>SELECT * FROM stream_view WHERE E_ID != '$E_ID' </code></pre> <p>Not really sure where to start so have struggled to figure it out myself</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload