Skip to content
Advertisement

How To Output results from a table where the data does not exist in the other table MYSQL

I have a table which places a client on a ‘grid’ with x and y coordinates from -10 to 10.

I need to select the grid sections which there are no clients. I have tried using NOT EXIST but it does not show me the data I need. i.e if empty gird section was at -1-8 it would not select it.

I have tried this way below:

Also I know this was not a well worded question but would appreciate any tips on how to rod it better…

Here is a SQLFiddle to show my environment and tables.

Advertisement

Answer

The grid table needs to have a row for each point in the grid. You only have rows for the points on the diagonals.

If you make the id column AUTO_INCREMENT, you can automate this with the following query:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement