5 messages in com.mysql.lists.mysqlRe: mysql 3, subquerie alternative
FromSent OnAttachments
Mark van Beek10 Jun 2004 10:19 
Mark van Beek10 Jun 2004 10:35 
SGr...@unimin.com10 Jun 2004 10:48 
Chris10 Jun 2004 10:50 
Pete McNeil10 Jun 2004 12:47 
Subject:Re: mysql 3, subquerie alternative
From:Pete McNeil (mads@microneil.com)
Date:06/10/2004 12:47:46 PM
List:com.mysql.lists.mysql

On Thursday, June 10, 2004, 1:20:03 PM, Mark wrote:

MvB> Hi,

MvB> For a project I'm creating a search function, the deal is this, a select MvB> query must be submitted and in this query a check must be done to confirm a MvB> previously found and accepted item is not shown anymore, a short version of MvB> the query I need is this:

<snip/>

MvB> I don't know if the above query gives the result I want for starters, but
if MvB> someone gets the idea and know a way to implement a query like this in
mysql MvB> 3 instead of mysql 4.1+ I'd like to know. I cannot just upgrade to mysql

I think what you are looking for is another table into which you can put your previous results. This might be a temp table, or an ordinary table that is keyed for your session data.

Once this is done, you would join the previous_results table with your new query and select records where the components of the previous_results query are NULL.

previously...

INSERT INTO previous_result ... data1,...

...

SELECT ... FROM data_table d LEFT JOIN previous_result p ON d.data1=p.data1 and

WHERE p.data1 IS NULL AND (other criteria)

The left join gives you everything you are asking for in your criteria. The "WHERE p.data1 IS NULL" restricts the results to those that do not yet exist in the previous data table (presuming data1 would never be NULL in your data).

Hope this helps, _M