Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

sub select in mysql

aldacoaldaco Member Posts: 5
Hi im trying to make a query using sub selects, but this feature is not supported in my mysql version. what im trying to do is to get all the records that appears in one table but not in the other table. im doing something like this:
SELECT *
FROM problema
WHERE (
problema.no_problema NOT IN (

SELECT calif.n_problema
FROM calif
WHERE calif.n_control = '03040925'
)
)


In my local machine it works, i have the latest version of mysql, but in the server its not working and im not able to update the version.
I hope you can tell me a different solution to do this query

thanks

Comments

  • SupergibbsSupergibbs Member Posts: 50
    Try this on your server to make sure you get the same results...
    [code]
    SELECT problema.*
    FROM problema
    LEFT JOIN calif
    ON problema.no_problema = calif.n_problema
    AND calif.n_control = '03040925'
    WHERE calif.n_problema IS NULL
    [/code]

    Basically this tries to match problema.no_problema and calif.n_problema, if calif.n_control = '03040925'. Then returns the ones where calif.n_problema IS NULL (same as NOT IN). I changed the SELECT to only select from problema, so the results should be identical except, perhaps the order.

    If you get the same number of records but it looks different, add an ORDER BY clause to check that the data is indeed the same.

    -Jesse
Sign In or Register to comment.