How To Add PK As Foreign Key To Existing Table

Dec 27, 2013

I have created two tables in phpMyAdmin 3.5.8.1. comments which stores comments users post on a website and registration which stores a users registration details (username, password, e-mail etc, etc).

I want to add the username field from the registration table as a foreign key to the comments table. How do I do this in phpMyAdmin?

View 3 Replies


ADVERTISEMENT

SQL 2012 :: Partition Existing Table On Foreign Key (datetime) Column?

May 28, 2015

Is it possible to partition an existing table on a foreign key (datetime) column? Also would partition switching work?

View 0 Replies View Related

Query To Only Display Information From One Table Where The Foreign Key Doesnt Exist In The Other Table.

Nov 28, 2006

I want to make a query, stored procedure, or whatever which will only display the primary key where there does no exist a foreign key in linked table.For example. If I had two tables with a one to many relationship.A [Computer] has one or more [Hard Drives]. I want to select only those computers which do not have a Hard Drive(s) associated with them. That is, show all computers where the Computer_ID field in the [Hard Drives] table does not exist. This seems simple but I'm drawing a blank here. 

View 1 Replies View Related

Transact SQL :: Delete Records From Table (Table1) Which Has A Foreign Key Column In Related Table (Table2)?

Jun 29, 2015

I need to delete records from a table (Table1) which has a foreign key column in a related table (Table2).

Table1 columns are: table1Id; Name.  Table2 columns include Table2.table1Id which is the foreign key to Table1.

What is the syntax to delete records from Table1 using Table1.Name='some name' and remove any records in Table2 that have Table2.table1Id equal to Table1.table1Id?

View 11 Replies View Related

SQL Server Admin 2014 :: Few Record Loss In Table Primary Key Where Same Records Exists In Foreign Key Table?

Jun 21, 2015

Previously same records exists in table having primary key and table having foreign key . we have faced 7 records were lost from primary key table but same record exists in foreign key table.

View 3 Replies View Related

Cannot Truncate Table 'Database.dbo.Table' Because It Is Being Referenced By A FOREIGN KEY Constraint..

Aug 23, 2006

Here is my issue I am new to 2005 sql server, and am trying to take my old data which is exported to a txt file and import it to tables in sql. The older database is non relational, and I had made several exports for the way I want to build my tables. I built my packages fine and everything is working until I start building relationships. I remove my foreign key and the table with the primary key will get updated for the package again. I need to update the data daily into sql, and once in it will only be update from the package until the database is moved over.

It will run and update with a primary key until I add a foreign key to another database.

Here is my error when running the package when table 2 has a foreign key.

[Execute SQL Task] Error: Executing the query "TRUNCATE TABLE [consumer].[dbo].[Client] " failed with the following error: "Cannot truncate table 'consumer.dbo.Client' because it is being referenced by a FOREIGN KEY constraint.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

View 3 Replies View Related

Transact SQL :: How To Alter Existing Table Column As Identity Without Dropping Table

Nov 20, 2013

I have created a table as below mentioned. Then I want to alter the ID column as identity(1,1) without dropping the table as well as losing the data.

create table dbo.IdentityTest
(
id int not null,
descript varchar(255) null,
T_date datetime not null
)

View 7 Replies View Related

Create An Extra Table (for Audit Purpose) For Every Existing Table In A Database

Mar 28, 2008

Hi all, please help. I m trying to create an "empty" table from existing table for the audit trigger purpose.
For now, i am trying to create an empty audit table for every table in a database named "pubs", and it's seem won't work.
Please advise.. Thanks in advance.

Here is my code:





Code Snippet

USE pubs

DECLARE @TABLE_NAME sysname
DECLARE @AUDIT_TABLE VARCHAR(50)

SELECT @TABLE_NAME= MIN(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_TYPE= 'BASE TABLE'
AND TABLE_NAME NOT LIKE 'audit%'
AND TABLE_NAME!= 'sysdiagrams'
AND TABLE_NAME!= 'Audit'
AND TABLE_NAME = 'sales'

WHILE @TABLE_NAME IS NOT NULL
BEGIN

SELECT @TABLE_NAME= MIN(TABLE_NAME) FROM INFORMATION_SCHEMA.Tables
WHERE TABLE_NAME> @TABLE_NAME
AND TABLE_NAME = 'sales'

SELECT @AUDIT_TABLE = 'Audit'+''@TABLE_NAME''


SELECT * INTO @AUDIT_TABLE
FROM @TABLE_NAME

TRUNCATE TABLE @AUDIT_TABLE
ALTER TABLE @AUDIT_TABLE ADD UserAction Char(10),AuditStartTime Char(50),AuditUser Char(50)


SELECT @TABLE_NAME= MIN(TABLE_NAME) FROM INFORMATION_SCHEMA.Tables
WHERE TABLE_NAME> @TABLE_NAME
AND TABLE_TYPE= 'BASE TABLE'
AND TABLE_NAME!= 'sysdiagrams'
AND TABLE_NAME!= 'Audit'
AND TABLE_NAME NOT LIKE 'audit%'

END
Thanks. ..

View 6 Replies View Related

Copying All Rows From One Table Into Another Existing Table And Overwriting Data

Feb 15, 2005

i have 2 tables (both containing the same column names/datatypes), say table1 and table2.. table1 is the most recent, but some rows were deleted on accident.. table2 was a backup that has all the data we need, but some of it is old, so what i want to do is overwrrite the rows in table 2 that also exist in table 1 with the table 1 rows, but the rows in table 2 that do not exist in table one, leave those as is.. both tables have a primary key, user_id.

any ideas on how i could do this easily?

thanks

View 1 Replies View Related

Tempoary Table Question - How To Create One With The Same Schema As An Existing Table?

Jul 28, 2006

Hello,

I'd like to create a temporary table with the same schema as an exiting table. How can I do this without hard coding the column definitions into the temporary table definition?

I'd like to do something like:

CREATE TABLE #tempTable LIKE anotherTable

..instead of...

CREATE TABLE #tempTable (id INT PRIMARY KEY, created DATETIME NULL etc...

I'm sure there must be a simple way to do this!

Many thanks,

Ben S

View 3 Replies View Related

SQL 2012 :: Importing Excel Table Into Existing Table?

Aug 25, 2014

I am using the DTS wizard and having problems importing excel into an existing table.

Problem is that various column in excel are defined as double in the wizard but in my db table it is defined as an integer.

How do I get around this issue so the data types in excel can match up accordingly to my defined data type in my db table?

The wizard does a bad job of guessing the correct data type.

I have heard of using a staging table to import from excel and using that as my source to import into my existing table.

View 8 Replies View Related

Columns In Primary Table And Foreign Key Table

Feb 12, 2007

mahesh writes "HI,

I am new to sql server.

can anybody help me

I have a table named tblqualificationmaster.

can i know the foreignkeys and the table related to this

tblqualificationmaster having foeign keys using stored procedure."

View 1 Replies View Related

Foreign Kew, How Do I Get To Know To Which Table

Apr 27, 2008

it is attributed ?
Hi everyone,
My table contains columns that are goreign keys to other tables. How can i tell to which table/column each fk is attributed ?
Thanks

View 4 Replies View Related

Foreign Key In A Table

Apr 11, 2008

For this example suppose than we a have a DB in SQL Server 2000 with the tables Client, Orders and DetailOrders. the field for each one are:

Client: id_Cliente, Name_client
Orders: id_Order, fk_client, date
DetailOrders: id_Detail, fk_Order, Product

Between all this tables exist one or more foreign key restriction but I don't know them. However I know than exist a row in the SYSOBJECTS (system table) per each one of the foreing key restriction, using this information I want to build a query than back to me something like this:

Type Table1 Field1 Table2 Field2
--------------------------------------------------------------------------------------------------------
FK Orders fk_Client Clients id_Client
FK DetailOrders fk_Order Orders id_OrderFK

Somebody can tell me hoy can i do it?

tks 4 help.
Leo.

View 4 Replies View Related

New Table To ASPNetDb.mdf And Foreign Key

Nov 30, 2006

I was thinking of adding tables to ASPNetDB.mdf and have one of those tables have column userid as a foreign key from aspnet_Users
When I try to create relationship in Diagram, I get error saying that "data typ properties does not match"
userid in aspNet_Users is uniqueidentifier and userid (fk) in new table is int
What should I use, should I do that at all?
 
Thanks

View 4 Replies View Related

Delete A Table With Foreign Key

Aug 25, 2007

Hi how do i to delete a table with a foreign key?
When i try to delete the table i get error 3726
 
any?

View 3 Replies View Related

Assigning Two Foreign Key To One Table

Jun 9, 2008

hi all
 
can we assign two foreign key to one table .
 
 

View 3 Replies View Related

Joining More Than One Table Without Foreign Key .

Dec 19, 2007

use default pubs database in sqlserver2000.
use authors table and publishers table.

Write a query to list first name, last of all authors
and name of the publisher (if any) present in the same city
as the author. If no publisher is present in the city
where the author is located then the column should contain a
NULL value. If there is more than one publisher in the city
where the author is located, then the details of
the author are to be repeated for each publisher.

but there is no field match between authors table and publishers table.

View 9 Replies View Related

2 Different Foreign Keys In One Table

Jun 13, 2006

There is itemlookup table, which stores item number and itemdescription. Also there is a child table, pricehistory, of theitemlookup table, which stores different prices and different dateranges. So it is one-to-many relationship. (Price can be stored morethan one with a different date range)And there is another table RequestItem that stores the foreign key ofthe itemlookup table to show the information of the itemlookup table.Then how do I know later which date range of the price was stored inthe RequestItem table? Since I only keep the foreign key of theitemlookup table, it will be impossible to keep track of the row of thepricehistory table if there are more than one data existed in thepricehistory table.Will it be a valid table structure to create a column for the foreignkey of the pricehistory in RequestItem table or any other ways tohandle this issue?

View 1 Replies View Related

Updating A Table With A Foreign Key

Sep 27, 2006

Hi,

I have a datatable with the following values:

ID

CompanyID

CompanyName.

Here ID is the foreign key. I was wondering if there was a way to update tables with foreign keys. Searching for stuff gave me something like update cascade. Can somebody please elaborate on that?

View 3 Replies View Related

Foreign Key Table References Per Table (Max 253)

Feb 22, 2008

I've just found out about the concept that a table should only be references by foreign keys a maximum of 253 times throughout the database. I was hoping someone could give me a better idea of the dangers of disregarding this recommendation.

In our database, we have a Users table, which contains all of the users of a given system. In nearly every other table in our database, we have a field to indicate which user created the record. This is a reference back to the Users table. But as the number of tables has grown, we've surpassed that 253 limit. All I can tell, practically, is that I can no longer delete from the Users table. The query will fail, telling me the query optimizer ran out of memory, and that I should simplify my query.

The Users table is the only table that even comes close to this number of foreign key references. I don't even mind being unable to delete from the table. I'm mostly wondering if there are other problems with my design that will cause issues?

Is there a better way to keep track of who created a record in the database? Is it bad design to reference my Users table in so many places?

Thanks,

View 1 Replies View Related

ORDER BY (field In Foreign Table)

Apr 4, 2008

Newbie question. Can someone show me an SQL statement that sorts the results of a query by a field in a different table?

CREATE TABLE `Table1`
(
`table1_id` INTEGER AUTO_INCREMENT ,
`table1_name` VARCHAR(255),
PRIMARY KEY (`table1_id`)
)

CREATE TABLE `Table2`
(
`table2_id` INTEGER AUTO_INCREMENT ,
`table2_name` VARCHAR(255),
`table2_table1` INTEGER,
PRIMARY KEY (`table2_id`)
)

ALTER TABLE `Table2` ADD FOREIGN KEY (`table2_table1`) REFERENCES `Table1`(`table1_id`);

What I'd like is something like:

SELECT * FROM Table2 ORDER BY "Table1(table2_table1).tabel1_name",table2_name

It's the section in double quotes that I can't figure out how to compose.

As an example, if Table 1 has
1, A
2, B
3, C

and Table 2 has
1, a, 2
2, b, 1
3, c, 2

then I'd like the sort to return
2, b, 1
1, a, 2
3, c, 2


TIA,

Stephen

View 2 Replies View Related

Update Table, Foreign Keys Etc

Aug 16, 2004

I have two tables as below. I want to update a quote and change the item for which it is for. So I want to do an update statement to change the cat_ref that the quote is for. However, when I do this I get a foreign key conflict with cat_ref in the item table. How do I get around this? Thanks


Code:

CREATE TABLE Item (
cat_ref VARCHAR(5)PRIMARY KEY,
descrip VARCHAR(50),
date_added SMALLDATETIME,
cat_type VARCHAR(20))


CREATE TABLE has_quote (
quote_id INT IDENTITY (1,1) PRIMARY KEY,
date_last_pricecheck SMALLDATETIME,
cat_ref VARCHAR(5)FOREIGN KEY
REFERENCES Item(cat_ref)
ON DELETE CASCADE,
first_name VARCHAR(10),
surname VARCHAR(10),
FOREIGN KEY (first_name, surname)
REFERENCES Customer(first_name, surname)
ON DELETE CASCADE
ON UPDATE CASCADE)

View 5 Replies View Related

Create Table With Foreign Keys

May 30, 2007

How do I create a table with a foreign key

View 6 Replies View Related

Foreign Key From Another Table In A Linked Server

Apr 19, 2008

Hi,

We're having a few linked servers in our company. some tables in one of the linked servers include columns (better saying, foreign keys) of tables in another server. I wonder if there's a way to create a foreign key referencing one column in another server. That is, suppose there's Column A in table A in Server A which references Column B in table B in server B, is there a way to create column A as foreign key referencing column B?

Any idea is appreciated.

View 3 Replies View Related

Foreign Key From Another Table In A Linked Server

Apr 19, 2008

Hi,

We're having a few linked servers in our company. some tables in one of the linked servers include columns (better saying, foreign keys) of tables in another server. I wonder if there's a way to create a foreign key referencing one columns in another server. That is, suppose there's Column A in table A in Server A which references Column B in table B in server B, is there a way to create column A as foreign key referencing column B?

Any idea is appreciated.

View 1 Replies View Related

Foreign Key References Invalid Table

May 15, 2008

Hey.

I'm trying to create some tables in my database but I'm getting some errors... The one which is causing the most trouble is Msg 1767, Level 16, State 0, Line 38
Foreign key 'ten_fk' references invalid table 'Tenant'.
I'm not sure why it's complaining... can anyone help me out here?

Cheers!

-- Mitch Curtis
-- A2create.sql

-- Set the active database to KWEA.
USE KWEA;

-- Drop existing tables (if any).
DROP TABLE Ownership;
DROP TABLE Tenant;
DROP TABLE Staff;
DROP TABLE Property;
DROP TABLE Property_Status_Report;
DROP TABLE Property_Owner;
DROP TABLE Placement_Record;
DROP TABLE Candidate_Tenant;
DROP TABLE Waiting_List;

-- Create new tables.
CREATE TABLE Waiting_List
(
waiting# INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
candidate_name VARCHAR(20) NOT NULL,
anticipated_start_date SMALLDATETIME NULL,
anticipated_end_date SMALLDATETIME NULL,
max_affordable_rent SMALLMONEY NOT NULL
);

CREATE TABLE Candidate_Tenant
(
candidate# INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
waiting# INT NULL,
name VARCHAR(20) NOT NULL,
phone_number INT NOT NULL,
required_property_type VARCHAR(10) NOT NULL,
CONSTRAINT w_fk FOREIGN KEY(waiting#) REFERENCES Waiting_List(waiting#)
);

CREATE TABLE Placement_Record
(
opening# INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
tenant# INT NOT NULL,
start_date SMALLDATETIME NOT NULL,
end_date SMALLDATETIME NOT NULL,
total_bonds SMALLMONEY NOT NULL,
weekly_rent SMALLMONEY NOT NULL,
CONSTRAINT ten_fk FOREIGN KEY(tenant#) REFERENCES Tenant(tenant#)
);

CREATE TABLE Property_Owner
(
owner# INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
name VARCHAR(20) NOT NULL,
phone_number INT NOT NULL
);

CREATE TABLE Property_Status_Report
(
address VARCHAR(30) NOT NULL,
report_date SMALLDATETIME NOT NULL,
weekly_rent SMALLMONEY NOT NULL,
month_rent_start_date SMALLDATETIME NOT NULL,
month_rent_end_date SMALLDATETIME NOT NULL,
maintenance_fee SMALLMONEY NOT NULL,
month_inspection_history VARCHAR(30) NULL,
CONSTRAINT ar_pk PRIMARY KEY(address, report_date),
FOREIGN KEY(address) REFERENCES Property(address)
);

CREATE TABLE Property
(
address VARCHAR(30) PRIMARY KEY NOT NULL,
staff# INT IDENTITY(1,1) NOT NULL,
type VARCHAR NOT NULL,
occupant_limit INT NOT NULL,
comments VARCHAR(30) NULL,
FOREIGN KEY(staff#) REFERENCES Staff(staff#)
);

CREATE TABLE Staff
(
staff# INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
manager# INT NOT NULL,
name VARCHAR(20) NOT NULL,
FOREIGN KEY(manager#) REFERENCES Staff(staff#)
);

CREATE TABLE Tenant
(
tenant# INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
staff# INT NOT NULL,
property_address VARCHAR(30) NOT NULL,
name VARCHAR(20) NOT NULL,
phone_number INT NOT NULL,
street VARCHAR(20) NOT NULL,
city VARCHAR(20) NOT NULL,
postcode INT NOT NULL,
category VARCHAR(10) NOT NULL,
comments VARCHAR(30) NULL,
FOREIGN KEY(staff#) REFERENCES Staff(staff#),
FOREIGN KEY(property_address) REFERENCES Property(address)
);

CREATE TABLE Ownership
(
address VARCHAR(30) NOT NULL,
owner# INT NOT NULL,
CONSTRAINT ao_pk PRIMARY KEY(address, owner#),
FOREIGN KEY(address) REFERENCES Property(address),
FOREIGN KEY(owner#) REFERENCES Property_Owner(owner#)
);

-- Display tables.
SELECT * FROM Waiting_List;
SELECT * FROM Candidate_Tenant;
SELECT * FROM Placement_Record;
SELECT * FROM Property_Owner;
SELECT * FROM Property_Status_Report;
SELECT * FROM Property;
SELECT * FROM Staff;
SELECT * FROM Tenant;
SELECT * FROM Ownership;
Errors:
Msg 3701, Level 11, State 5, Line 8
Cannot drop the table 'Ownership', because it does not exist or you do not have permission.
Msg 3701, Level 11, State 5, Line 9
Cannot drop the table 'Tenant', because it does not exist or you do not have permission.
Msg 3701, Level 11, State 5, Line 10
Cannot drop the table 'Staff', because it does not exist or you do not have permission.
Msg 3701, Level 11, State 5, Line 11
Cannot drop the table 'Property', because it does not exist or you do not have permission.
Msg 3701, Level 11, State 5, Line 12
Cannot drop the table 'Property_Status_Report', because it does not exist or you do not have permission.
Msg 3701, Level 11, State 5, Line 13
Cannot drop the table 'Property_Owner', because it does not exist or you do not have permission.
Msg 3701, Level 11, State 5, Line 14
Cannot drop the table 'Placement_Record', because it does not exist or you do not have permission.
Msg 1767, Level 16, State 0, Line 38
Foreign key 'ten_fk' references invalid table 'Tenant'.
Msg 1750, Level 16, State 0, Line 38
Could not create constraint. See previous errors.

View 4 Replies View Related

Lookup Table Foreign Key Null

May 1, 2007

I'm using SQL Server 2000. I have an EXTERNAL_FUNDING table and an EXTERNAL_FUNDING_TYPE table. The DDL for the tables is listed below. Each EXTERNAL_FUNDING record has a type field, which is a foreign key to a record in the EXTERNAL_FUNDING_TYPE table. However, I would like for the type to be allowed to be null. When displaying the data, if the type is null, I'd like to show blank text. Here is the query I'm trying to use:
SELECT EXTERNAL_FUNDING.id, date_requested as [Request Date],source as [Source/Sponsor],EXTERNAL_FUNDING_TYPE.type AS [Type],amount as [Amount], granted as [Granted]
FROM EXTERNAL_FUNDING,EXTERNAL_FUNDING_TYPE
WHERE (project_id = @project_id) AND
(EXTERNAL_FUNDING.type = EXTERNAL_FUNDING_TYPE.id)
ORDER BY date_requested ,source,type

But this query does not return the records with NULL for the type field. Can someone explain to me how I can also return the rows with a NULL type? Thanks!

Table DDL:
CREATE TABLE [dbo].[EXTERNAL_FUNDING] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[project_id] [int] NOT NULL ,
[date_requested] [datetime] NULL ,
[source] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[type] [int] NULL ,
[amount] [money] NULL ,
[granted] [bit] NULL ,
[date_granted] [datetime] NULL
) ON [PRIMARY]

CREATE TABLE [dbo].[EXTERNAL_FUNDING_TYPE] (
[type] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[id] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]

View 2 Replies View Related

Assigning Foreign Key To New SQL Server Table

Aug 31, 2005

HiI am creating new SQL Server Tables using SQL Server 2005. I have setprimary key to the tables .But I do not know how to assign Foreign keyto the tables .I need to do some joins later and that is why I have toput Foreign key to the table . The Primary key is visible and can beassigned easily .But How do I assign foreign key .Thanks*** Sent via Developersdex http://www.developersdex.com ***

View 3 Replies View Related

Problem In Table With Two Foreign Keys

Feb 5, 2008

Hello,


I have a very elementary question on table design. This screenshot (which is part of a larger diagram) sets the context of the question.




There are two distinct groups of products with different attributes, hence two separate tables: Products_A and Products_B.
There's a third table that keeps track of daily production (DailyProduction), which must accept items from either product table. Now, my question is: How do I relate these two tables to "DailyProduction" ? If I place a double-constraint with two foreign keys, then I get an error whenever I attempt to insert a record in DailyProduction. For example, if the new item is of "Products_A" type, then the error message from SSMS is:


No row was updated.

The data in row 1 was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_DailyProduction_Products_B". The conflict occurred in database "MyDatabase", table "dbo.Products_B", column 'ProductB_ID'.
The statement has been terminated.


Correct the errors and retry or press ESC to cancel the change(s).


It's clear that the error message makes sense as SQL is trying to apply BOTH constraints. It's one AND the other, not one OR the other. Now, how do I remedy this ? What would be the most appropriate way to relate the three tables ?


Thanks.

Fernando

View 3 Replies View Related

Updating A Table Having A Foreign Key Constraint

Nov 10, 2006

Hi

I am trying to update tables "Table A" & " TableB" with a new value for a particular column1. Now "TableA" contains a foreign key "FK1" defined on it and is referencing another table "Table B" containing the similar column "Column1"

Because of this constraint I was not able to update TableA and TableB. My question is

1) If i wanted to go ahead with this update, what are the possible ways?

2) If only solution is to drop the constraint. Then How do i know the definition for this particular Foreign key, i mean it may refer some columns in Table B. I wanted to know the complete definition of it so that i can rebuild the constraint after the update. Right now i can see only the constraint name when i use sp_help TableA. But how do i know the complete reference made by this foreign key.



Early reply is much appreciated



Thanks!

View 3 Replies View Related

Transact SQL :: Untrusted Foreign Key In Table

Sep 2, 2015

I am seeing untrusted foreign key in one of my tables in a dev environment. To fix it I tried to run

ALTER TABLE [dbo].[TableName] WITH CHECK CHECK CONSTRAINT [ForeignKey]

But I am getting the below error

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "foreignkey". The conflict occurred in database " DBname", table "dbo.tablename", column 'columnname'.

View 6 Replies View Related

How To Retrieve Data From A Second Table With No Foreign Key

Oct 5, 2007



I have 4 tables I am pulling data from. Table A and B can be joined and Table C and D can be joined via foreign keys but A and/or B can not be Joined to C and/or D via foreign Key.

My statement basically looks like this to start


SELECT s.HTENANT, s.HPROP, s.HUNIT, s.SHEADNAME3B, s.DTOT7I
FROM H8summ S join tenant t on s.htenant = t.hmyperson

And returns this :


29226 128 20577 Almukhtar, Khadijah M 4242.00
26574 128 17980 Archie, Mary 20218.00

The last number is the key it is the income.

In another table we have an income limit table setup that would have the low, medium and high settings for the range.

For instance it may have 11400 as the elimit attribute and say 22000 as the vlimit attribute.

Then in the fourth table we the description that can be linked back to the income limit table via the hinclimit attribute. In this case the desc attribute would be ELI for elimit and VLI for vlimit.

So I want to take the income compare it to the income limit table and then return the description

The output would look like this :
29226 128 20577 Almukhtar, Khadijah M 4242.00 eli
26574 128 17980 Archie, Mary 20218.00 vli

I just not sure how to reference the income limit table without the foreign key in the from statement. When I just add it it returns 6 rows for each person (number of rows on the income limit table)




View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved