<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>Hmm. I&#39;m not that familiar with MySQL, but in PostgreSQL the way to determine what you want is<br><br></div>select<br></div><div>   <a href="http://animal.id">animal.id</a><br></div>from<br></div>   animal<br></div>left join<br></div>   food<br></div>on<br></div>   <a href="http://animal.id">animal.id</a> = food.animalid <br></div>where<br></div>   <a href="http://food.id">food.id</a> is null<br>;<br><br><br></div>Writing SQL queries takes some practice.  One handy tip I&#39;ve found is to write the &quot;from...&quot; part first, then go back and fill in what columns you wish to select.<br><br></div>Doing anything based on the numeric value of the &quot;id&quot; field is a Bad Idea.  In most relational databases, that field just increments when you add a record to your table.  It never decrements when you delete records.  That means that the  ID value itself is useless in determining what is or is not in a table.   It&#39;s only useful when it&#39;s in another table -- hence the name, &quot;Relational&quot;.<br><br><br></div><div>Your current table setup also breaks down if you add -- say -- a goat which wants to eat the same things as the giraffe. You&#39;re more likely to have several animals linked to the same foods than several foods linked to the same animal.  Don&#39;t you really want a &quot;FoodFk&quot; in the &quot;animal&quot; table?  Then you could have lots of animals which eat the same thing.  Of course, I reckon in reality you&#39;d need a jump table to link foods and animals:<br><br></div><div>food_animal { integer animalid references animal(id), integer foodid references food(id) }<br><br></div><div>Then you could have lots of different foods and lots of different animals all linked together.<br></div><div><br><br></div>-- CHS<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 13, 2015 at 1:52 PM, David S Jackson <span dir="ltr">&lt;<a href="mailto:deepbsd.ale@gmail.com" target="_blank">deepbsd.ale@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I&#39;m a MySQL newbie.  I&#39;m just starting to use Python to talk to MySQL databases, but first I need to understand the MySQL query language!<br>
<br>
<br>
So, I have two tables:  (zoo) animal and food.<br>
<br>
animal has the columns ID, NAME, FAMILY, WEIGHT<br>
<br>
food has  ID, ANIMALID, FEED<br>
<br>
<br>
So if I go: select id, name, family, feed from animal JOIN food ON <a href="http://animal.id" target="_blank">animal.id</a>=food.animalid;<br>
<br>
<br>
I get something like:<br>
<br>
ID   NAME        FAMILY      FEED<br>
1    Seymore   Snake        mice, leaves<br>
2    Gerard      Giraffe       leaves, grass<br>
...<br>
etc<br>
<br>
So, if I have a situation where I want to see whether an animal has been added the animal table but may have not been added to the food table, how would I compose that query?<br>
<br>
That is, the animal could have been added to the animal table and could get an id, say 10, but the food table could have 20 foods already entered and the animal-id would be used several times.<br>
<br>
I was thinking, is there a way I can ask, &quot;does the highest <a href="http://animal.id" target="_blank">animal.id</a> number equal the highest food.animalid number&quot;?  If not, what animal is not getting fed?<br>
<br>
Dave<br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org" target="_blank">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/<u></u>listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/<u></u>listinfo</a><br>
</blockquote></div><br></div>