Author |
Topic |
neon20
Starting Member
2 Posts |
Posted - 2007-04-04 : 06:46:41
|
hi friendsi have a query like thisquery1="select co.*, ct.*, from contacts co, enquiries en, contactPersonType ct where co.co_contactId=en.en_contactId and co.co_contactType=ct.ct_contactTypeId"i want to display only the contact persons details who made enquires.this gives me duplicate records. im not displaying enquiry details. how can i use distinct with this?thank youneon |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-04 : 06:52:43
|
1. I don't see need to use D-Sql here2. Use JOIN clause instead of adding join conditions in WHERE clause. It is more readable and less prone to errors3. Post Table structures, sample data and expected output when posting any question.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-04-04 : 07:11:01
|
4 Dont select all columns from all table instead select only required columns5 Make use of stored procedure with parameter than using concatenated sql statementsMadhivananFailing to plan is Planning to fail |
|
|
neon20
Starting Member
2 Posts |
Posted - 2007-04-04 : 09:52:27
|
hi thank you for the reply. i tried left join. it doesnt work.giving error-------Error Type:Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'co.co_ContactID = en.en_contactID LEFT JOIN contactPersonType ct on co.co_ContactType = ct.ct_contactTypeID'.--------i know i get duplicates because i use * i can use distinct if i use individual colums in the query instead of *.as i have too many fields to select and the query itself is lengthy i use * instead.here is my actual queryquery1="select co.*, ct.*, cn.* from contacts co left join enquiries en on co.co_contactId=en.en_contactId left join contactPersonType ct on co.co_contactType=ct.ct_contactTypeId left join country cn on co.co_country=cn.ct_countryId"all the ID fields are numeric and both the contacts and enquiries tables have atleast one memo field.thanks youneon |
|
|
X002548
Not Just a Number
15586 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-23 : 05:09:48
|
SPAM! SPAM!! SPAM!!!Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-23 : 05:10:17
|
3 posts, 3 spam. A new record?Peter LarssonHelsingborg, Sweden |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2007-04-23 : 07:35:25
|
(Spammy post deleted)===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
|
|
|