Jump to content

Recommended Posts

Hi there,

 

Im trying to run this query:

 

SELECT BreedID FROM breed WHERE breed.AnimalTypeID = animal.AnimalTypeID

 

Basically the outcome is that the BreedID's records are displayed where the breed.animaltypeid is the same as animal.animaltype.id

 

i can an error saying: "#1054 - Unknown column 'animal.AnimalTypeID' in 'where clause' "

 

 

I started playing around with it my making few changes:

 

SELECT BreedID FROM breed, animal WHERE breed.AnimalTypeID = animal.AnimalTypeID

 

This results in this error message: "#1052 - Column 'BreedID' in field list is ambiguous"

 

 

What am i doing wrong?? Why isnt the query working???

 

Please help

 

Thank You

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/87762-query-not-working/
Share on other sites

Hi there,

 

Thank you for the reply, Yes i see what you mean your code works very well.

 

This however still doesnt give me the results i need because the query NEEDS not only compare the breed.animaltype with animal.AnimalTypeID But it also MUST ensure the RELEVANT animal record  is compared.

 

The results at the moment will display all of the breeds because it is queryng all records in the Animal table and not just the relevant animal record!

 

How can i do this???

 

 

To try and overcome this problem i need to some how add a conditional somewhere to the query so it only brings up ONLY the most recent Animal record.....

 

Then knowing there is only 1 animal.AnimalTypeID (as most recent updated record) that needs to be queried against all breed.AnimalTypeID's

 

So the list of breeds that are displayed are the ones that only relate to the animal.AnimalTypeID (which is only 1)

 

Here is a query that will select the correct animal record:

 

mysql_select_db($database_woodside, $woodside);

$query_animal = "SELECT * FROM animal ORDER BY AnimalID DESC";

$animal = mysql_query($query_animal, $woodside) or die(mysql_error());

$row_animal = mysql_fetch_assoc($animal);

$totalRows_animal = mysql_num_rows($animal);

 

 

And here is the other query (so far) that selects the breedID WHERE breed.AnimalTypeID = animal.AnimalTypeID:

 

 

mysql_select_db($database_woodside, $woodside);

$query_Recordset1 = "SELECT BreedID FROM breed WHERE breed.AnimalTypeID = AnimalTypeID";

$Recordset1 = mysql_query($query_Recordset1, $woodside) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

 

 

 

Stay with me.....Please...

:)

 

Thank You

 

Link to comment
https://forums.phpfreaks.com/topic/87762-query-not-working/#findComment-448969
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.