Web Development
16 replies
by roc180
Sounds like you are doing a many to many join in your query. To fix the problem look at your join criteria, try to uniquely define the join by specifying multiple fields to join on:
(T1.id=T2.id AND T1.name=T2.name),
or use a GROUP BY clause to flatten your results :
SELECT F1,F2,F3
FROM T1
WHERE F1=Something
GROUP BY F1,F2,F3
If this dosen't solve your problem you cansend me the SQL and your tables and I can take a look at that.
Good Luck
Neal Martinelli
by tlscruggs
by donq
by tlscruggs
by davram
Why don't you just post the SQL query, also? It would be a lot easier for the rest of us to point you the error.
You probably should provide us with some informations about the technical environment you are using, too.
Thanks.
by tlscruggs
by ladyskydiver
by tlscruggs
by dglundman
by tlscruggs
by tlscruggs
by dglundman
The SQL construct ? SELECT DISTINCTROW ?. anyfield,anyfield,anyfield, * FROM table1, table2, table3 ?, Will likely produce multiple duplicate records, with or without the DISTINCT, because of the ?*? and the unrestricted request, ie no WHERE clauseand/or no JOINs.
My first suggestion is to only use ?*? if you really mean it. In Ms SQL, if you have two tables; one with 4 records and the other with 3 records, a ?SELECT * FROM table1,table2? will likely return 12 records or rows.
I am guessing from the sample you sent that you are using Access or some other SQL Compliant Object Query Language. SQL provides a number of runtime methods of joining related tables. My preference is using the WHERE clause.
With Ms SQL 7.0 & 2000, Enterprise Manager you get the SQL Query Analyzer Tool which is useful in optimizing Queries.
The clause might be something like ? SELECT DISTINCT * FROM table1,table2,table3 WHERE table1.columnA = table2.columnC AND table2.columnH =* table3.columnK ? This is a one-to-one relationship between table1 and table2 and a one to many relationship between table2 and table3. The possibilities are endless.
Of course Ms SQL Query Tools should warn you if you try to construct a circle Join, orother illegal Join, but they won?t tell you about incomplete Join Paths. I like to try a Query in the Analyzer before I place it in any code or stored procedure.
An example of an incomplete Join is where you define the JOIN for the first two tables but not the third. That would cause all the rows (records) from the first two tables to be repeated for every row from the third table.
[see full response in email]
by tlscruggs
by tlscruggs
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending