I'm selecting data from two different rows in the same table using a single sql.
"id" "borrowMax" "holder" "category" "country"
"1" "2" "0" "3" "US"
"2" "0" "1" "10" "US"
What I'm trying to do works out to this.
select id, holder from mytable where id = 2
select borrowMax from mytable where id = (
holder from the above select, in this case it's 1
) and category = 3
The way I do it after looking at examples online is
SELECT col1.id, col1.holder, col2.borrowMax
FROM collection_db col1
JOIN collection_db col2
ON col2.holder = col1.id
WHERE col1.id = 2 //Here, 2 is the value supplied by me
AND col2.category = 3
Sure, this works. But since it's something I pieced together myself, I have my doubts. How would you do something like this? Am I on the right track? (I'm sure I'm not).
JOIN. Should it beINNER JOIN?JOINis OK: when you specify theON ...condition,JOINis equivalent toINNER JOIN. It's more or less explained here.