butenhjo2018 butenhjo2018 - 6 months ago 7
SQL Question

Get Value from another column but same row in SQL

I have a sql database that is setup like this:

+------+------+
|code |used |
+------+------+
|1021 |0 |
+------+------+
|2235 |0 |
+------+------+
|3324 |0 |
+------+------+
|1914 |1 |
+------+------+
|2215 |1 |
+------+------+


I am wondering what statement can I run in Java code, so that I get the find the row that has the code that is input into the query, and then get the value of used, either 0 or 1, and return that value.

So if I am checking the code 1021. It would look through all the codes to find that row with that as the code, and then go to the used column, and return that value. So for 1021, it would return a 0.

Answer

As requested, i have posted it as a solution.

select used from yourtable where code=:inputvalue
Comments