Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

Hope someone can help me. I have a Database table with the following data in

company site building camera cameraentry cameraname valid
1       1     1       1      1           CAM A      0
1       1     1       2      1           CAM B      0
1       1     1       1      2           CAM C      0


What I need is to get all the cameranames per camera for valid 0, but I need the name of the max cameraentry

So in my results will read:

CAM B
CAM C

Thanks in advance.
Posted
Updated 9-May-12 4:03am
v2
Comments
Corporal Agarn 9-May-12 9:57am    
What have you tried so far?
[no name] 9-May-12 10:26am    
You could select everything and then read out every dataset that has valid = 0. (Well, not the entire Dataset, since you only want the name) Although I'd not recommend that.

You should try to select what you need and nothing more. (Select the row you want the value from and only select datasets where valid = 0, as you stated)

These links should help you find the solution: (It's quite easy)
SQL SELECT Statement[^]
SQL WHERE Clause[^]

1 solution

If I understood the question correctly, you could try something like:
SQL
SELECT *
FROM   YourTableName A
WHERE  A.Valid = 0
AND    A.CameraEntry = (SELECT MAX(B.CameraEntry)
                        FROM   YourTableName B
                        WHERE   B.Valid = 0)

Note that the query above can return several rows if the same value can be repeated in CameraEntry
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900