Query my DB

Results 1 to 3 of 3

Thread: Query my DB

  1. #1
    dd(dumbo) Guest

    Default Query my DB

    I have two tables in my DB, how do I query the DB to find a BT for all PCT in table 2, which by the way contains 2600 records?<BR>I&#039ve joined PCT TO PCT but that doesn&#039t seem to work because of the POR.<BR>Notice in TB1, pct 11611 is alone with no portions - TB2 pct 11611 is broken into 2 portions, A & B, this is because both portions of pct 11611 have the same BT. What if there is a PCT with PORtions that have a different BT like PCT 11616 in TB1? <BR><BR>The goal is to BT all the PCT (including POR) in TB2. the problem is in TB1. If a PCT is made up of the same BT it will not show the POR. <BR><BR><BR><BR>Table 1(bt_pct) - columns:<BR><BR> BT PCT POR<BR> 001 11611<BR> 001 11616 A<BR> 002 11616 B<BR><BR><BR>Table 2(pct-por) - columns:<BR><BR> PCT POR FLAG AREA <BR> 11611 W RIVWARD2<BR> 11611 A N RIVWARD2<BR> 11611 B N RIVWARD2<BR> 11616 W " "<BR> 11616 A N " "<BR> 11616 B N " "<BR><BR>-------------------------------------------<BR><BR>If anyone understands what I need, PLEASE reply!!!!!!<BR><BR>This is the code for the query I came up with:<BR><BR>SELECT [bt_pct].[BT], [bt_pct].[PCT] AS bt_pct_PCT, [bt_pct].[POR] AS bt_pct_POR, [pct-por].[PCT] AS [pct-por_PCT], [pct-por].[POR] AS [pct-por_POR], [pct-por].[FLAG], [pct-por].[AREA NAME]<BR>FROM bt_pct INNER JOIN [pct-por] ON [bt_pct].[PCT] =[pct-por].[PCT];

  2. #2
    Join Date
    Dec 1969

    Default RE: Query my DB

    Your tables are redundant and may need to be redesigned. It looks like the link between them is a combination of the PCT field and the POR field. I&#039m trying to visualize what those acronyms mean to put it in a real world perspective, but I dont have enough info. If you could post what kind of data these tables hold, I could get a mental picture of what your trying to accomplish.

  3. #3
    Join Date
    Dec 1969

    Default RE: Query my DB

    What I am trying to do is assign a BT(BallotType) to a PCT(PreCincT). I think my trouble is in the column PORtion.<BR><BR>Table 1(bt_pct) has all BT&#039s and WHOLE precincts. A whole PCT in example is 11401, 11402, 11403, 11616(A), 11616(B). The A and B are called PORtions, they are listed as whole pcts here because they are made up of 2 different BT&#039s. The A and B and are in their separate columns (which is where I think the problem is).If a Precinct (including PORtion PCTs) is made up of (1) BT it is consolidated into a WHOLE PCT, for instanct 11508A, 11508B are of the same BT they are now PCT 11508.<BR><BR>Table two has listed ALL precincts, including all portions whether they are of the same BT or different BT&#039s. So for instance, PCT 11508A, 11508B, C, D are of the same BT but each are considered a PCT in itself. Table1 has consolidated PCTs therefore there is no way of knowing which of the whole precints have PORtion PCTs. Except for the PCT&#039s that are made up of 2 of more BT&#039s, they are listed as individual PCt&#039s.<BR><BR>I really hope I made some sense of this because I really need your help and I appreciate it as well.<BR><BR>Here is a visual:<BR>TABLE 1 - WHOLE PCT<BR><BR>BT PCT POR<BR>1 11400<BR>1 11401 <BR>1 11403<BR>1 11508<BR>1 11616 A<BR>2 11616 B<BR>2 11617<BR><BR>TABLE 2 - ALL PCTS<BR><BR>PCT POR NAME<BR>11400 <BR>11401<BR>11403<BR>11508 A<BR>11508 B<BR>11508 C<BR>11616 A<BR>11616 B<BR><BR>HOPE THIS HELPS;)<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts