There is a task: to keep car comparisons.
Did the table:

id car_id_1 car_id_2 count - общее кол. по данному сравнению автомобилей 

So, if I, for example, added an Audi 3 vs BMW i3, then I cannot get the same comparison on the BMW i3 vs Audi 3.

Half a day puzzled, so did not find the answer, so that in one request using LIMIT .

I am sure that I didn’t make a structure for this correctly.

  • Show what happened in half a day. Add a query directly to the question. - 0xdb 4:34 pm
  • why limit if you are looking for only one where (car_id_1=X and car_id_2=Y) or (car_id_2=X and car_id_1=Y) - Mike
  • answered below, thanks - serg.test

1 answer 1

Change the structure, make 2 tables.

The first is a comparable machine. (Machine ID - Comparison ID)

The second is the number of comparisons. (Comparison ID - quantity)

Such a structure, besides logic and convenience, will allow to compare any number of objects (say, three cars at once).

  • That's what I thought of such a plan, but I might already be tired for the day, but I don’t understand how I can get the same comparisons. The deeper essence is to get the cars that are in certain "dachshunds". pastebin.com/j6aWJMtL - serg.test
  • The word "tax" in the Russian language has 2 meanings. And any of them looks in your phrase ... well, let's say that - not in the case. - Akina
  • if you specify Taxonomy (Wordpress - codex.wordpress.org/Taxonomies ) - serg.test
  • Well, with the word decided ... it remains to understand what is hidden under the resulting phrase. And it is better if you think in advance that only you know the subject area, the task, and understand the slang applied to it. - Akina
  • I will help. Taxonomy is like a category, and the term taxonomy is a section of this category. In this query, I already know that I need to get electric cars, this is term_taxonomy_id. - serg.test