php - SQL duplicate row -


I have a big filter with many options and want to generate SQL for automaticle and without any code without query.

Obtain:

  SearchView = ABC and Title = ABC and Description = ABC and Category = 1 and Subcategory = 2 & amp; Zip = 7 & amp; City = K & amp; Country = DE  

SQL:

  select activity * Activity, subcategory, city, country, like WHERE activity.title '% abc%' or activity. Details like '% ABC%' and subcategory. SBID = 2 and the city. Zip '% 7%' and like the city. '% For%' and country. C. Shortcode = 'D'  

With this option, I have 1 row in my database, the answer is many times many times.

I know that SQL duplicates a line when a table is not used in WHERE clausel - but why do they do this now and how can I solve that?

EDIT: I have an ER, but the database is in German (school project), maybe it helps you understand:

Thanks!

You are doing a cross product by selecting multiple tables. SQL will combine each row from one table to each row in the second table.

For example in a database in the table

  | ------ | ---------- | | IDA | Text A | | ------ | ---------- | | 1 | Foo | | 2 | Baré | | ------ | ---------- |  

and Table B

  | ------ | ---------- | | IDB | Text B | | ------ | ---------- | | 1 | Fubi | | 2 | Barb | | ------ | ---------- |  

When you do

  SELECT * to a, b  

you will get

  | ------ | ---------- | ------ | ---------- | | IDA | Text A | IDB | Text B | | ------ | ---------- | ------ | ---------- | | 1 | Foo | 1 | Foo | | 1 | Foo | 2 | Baré | | 2 | Baré | 1 | Fubi | | 2 | Baré | 2 | Barb | | ------ | ---------- | ------ | ---------- |  

You add to add these rows to the rows. This means that you tell in your query which rows are in place, you can do that in the straight line WHERE of the JOIN clause or the joint contract without it. For example you will do

  SELECT * to a, b WHERE a.idA = b.idb - or SELECT * to a. AIDA = B.IDB on BEd  

You will only get 2 rows.

  | ------ | ---------- | ----- - | ---------- | | IDA | Text A | IDB | Text B | | ------ | ---------- | ------ | ---------- | | 1 | Foo | 1 | Foo | | 2 | Baré | 2 | Barb | | ------ | ---------- | ------ | ---------- |  

To answer your question: JOIN / WHERE to connect you to your table activity , subcategory The Client will have to support city and country according to your database schema.

I do not have your table structure, but for example such sections:

  where ... and city.country_id = country.id and activity subcategory_id = Subcategory.id and ...  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -