For sure you declared the wrong table or joined the wrong column. A join ill not create a row from thin air.
Try to remove a join each time to find the offending one
سؤال
I created a view of 5 tables. All of the tables have the same UNIQUE KEY. When I select COUNT(*) for a given ID in each table there is ONE record per ID in each table.
For example: select count(*) from general where id = '523d8bab7' returns 1. I have 4 other tables. When I run the select COUNT I get a count of one for any given ID.
When I create the view I get 4 rows for each ID. IT should be just one row per ID.
Here is a sample of the SQL I use :
SELECT
table1.id,
table1.field1,
table1.field2,
table1.field3,
table2.field1,
table2.field2,
table2.field3,
table3.field1,
table3.field2,
table3.field3,
table3.field4,
table4.field1,
table4.field2,
table4.field3,
FROM table1
INNER JOIN talbe2 on table1.id = table2.id
INNER JOIN table3 on table1.id = table3.id
INNER JOIN table4 on table1.id = table4.id;
How do I create a view/sql that will create ONE row in the view per UNIQUE ID? Right now I get 4 rows in my view per ID.
لا يوجد حل صحيح
نصائح أخرى
For sure you declared the wrong table or joined the wrong column. A join ill not create a row from thin air.
Try to remove a join each time to find the offending one