sqlite - return all columns for max of one column without repeats
<p>Im using Python to query a SQL database. I'm fairly new with databases. I've tried looking up this question, but I can't find a similar enough question to get the right answer.</p>

<p>I have a table with multiple columns/rows. I want to find the MAX of a single column, I want ALL columns returned (the entire ROW), and I want only one instance of the MAX. Right now I'm getting ten ROWS returned, because the MAX is repeated ten times. I only want one ROW returned.</p>

<p>The query strings I've tried so far:</p>

<pre><code>sql = 'select max(f) from cbar'  
# this returns one ROW, but only a single COLUMN (a single value)

sql = 'select * from cbar where f = (select max(f) from cbar)'  
# this returns all COLUMNS, but it also returns multiple ROWS
</code></pre>

<p>I've tried a bunch more, but they returned nothing. They weren't right somehow. That's the problem, I'm too new to find the middle ground between my two working query statements.</p>

<p>In SQLite 3.7.11 or later, you can just retrieve all columns together with the maximum value:</p>



<pre class="lang-sql prettyprint-override"><code>SELECT *, max(f) FROM cbar;
</code></pre>

<p>But your Python might be too old. In the general case, you can sort the table by that column, and then just read the first row:</p>

<pre class="lang-sql prettyprint-override"><code>SELECT * FROM cbar ORDER BY f DESC LIMIT 1;
</code></pre>

python sqlite max