|
Thread: Sql
-
Feb 24th, 2013, 03:00 AM
#1
Thread Starter
Frenzied Member
Sql
Hi, anyone up with sql? Trying to develop a query and can't quite get a join right ?
SELECT [Prefix] & [Subletter] AS ff, tblEPData2.TrackNum
FROM tblEPData2, tbl1964
WHERE ((([Prefix] & [Subletter]) Like "EP64*") AND ((tblEPData2.TrackNum) Like "B*"))
ORDER BY [Prefix] & [Subletter];
But I need to output another table containing ff. (So my whole approach may be quite wrong)
Thanks
-
Feb 24th, 2013, 04:56 AM
#2
Lively Member
Re: Sql
Are tblEPData2 and tbl1964 joined by particular fields? If so, add this in your WHERE clause : AND (tblEPData2.field1 = tbl1964.field2)
And please explain what you mean by "need to output another table containing ff"
-
Feb 24th, 2013, 05:28 AM
#3
Thread Starter
Frenzied Member
Re: Sql
Hiya, thanks for reply
There's no join (yet) not sure where it should go. At the moment tbl1964 is sitting in design mode grid unused.
ff (if present) will exist in tbl1964 as both Prefix & Subletter in one field. But in tblEPData2 they are 2 separate fields
It's the ones in tbl1964 I want to have as my recordset source.
If I'm not making sense, let me know? Sometimes its hard to explain !
-
Feb 24th, 2013, 05:32 AM
#4
Lively Member
Re: Sql
The general idea of a relational database is to NOT have duplicate data in different tables. You put it in one place, and join to it as required
-
Feb 24th, 2013, 05:41 AM
#5
Thread Starter
Frenzied Member
Re: Sql
That may be so, but isn't what I have.
-
Feb 24th, 2013, 01:36 PM
#6
Lively Member
Re: Sql
Is it someone else's database, or your own (as suggested by "tbl1964 is sitting in design mode grid unused") ... so it's not too late to re-organise it?
-
Feb 24th, 2013, 03:29 PM
#7
Re: Sql
did you test if the combined values to ff matched the single field?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 24th, 2013, 07:31 PM
#8
Thread Starter
Frenzied Member
Re: Sql
>Is it someone else's database, or your own
I'm designing a query (hopefully) to achieve a result. Well, more than that - I will get the desired result but exactly how I'm still looking for. The data (tables) already exist and can't be changed.
In any case, it is worthwhile to see how what I want to do can be done.
Pete, I don't follow. The combined values of ff will either match or be missing from tbl1964.
One problem I have is the join properties (as described in Access) have never made sense to me. But I can't experiment because ff isn't a field I can join AFAIK. ff is two fields added together. Maybe I have to create another field (with both values) and join that to it's matching field in table 2?
All good fun... ploughing on....
-
Feb 24th, 2013, 08:00 PM
#9
Thread Starter
Frenzied Member
Re: Sql
We're there! My inexperience using 2 tables was to blame - and thinking I needed JOIN.
SELECT tbl1964.Serial, tblEPData2.TrackNum
FROM tbl1964, tblEPData2
WHERE (((InStr([tbl1964].[Serial],[tblEPData2].[Prefix]))<>False) AND (Right([tbl1964].[Serial],1)=[tblEPData2].[SubLetter]) AND ((tblEPData2.TrackNum) Like "B*"));
I guess it all makes sense when you see it like that !
Regards, ABB
-
Feb 25th, 2013, 06:11 AM
#10
Re: Sql
Whenever there are fields from two or more tables/views returned by a query, you do need a Join... but they don't have to be the kinds that the Access interface can generate (which is only 'simple' Inner/Outer Joins).
The kind of thing you have done is an Inner Join, but much more complicated (and slower to run) than the kind that Access can create automatically.
There are other types of Joins too (such as Cross), but Inner/Outer are by far the most common (and among those, joining on an entire single field is the most common).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|