|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Joining of two tables
hi
I have site in php.I want to join two tables with left join.How possible. One table comprises empid,deptt,empname etc. second table consist city state country etc. Plz solve this query. thanks Last edited by Shadow Wizard : May 9th, 2008 at 04:16 AM. Reason: removed signature |
|
#2
|
||||
|
||||
|
Well, given the column names as you have in the post, you cant join these tables -- you need to have data that some how relates the the two tables. For example, given your two tables Employee and Address, you probably have a 1 to many (1-M) relationship between Employee and Address (I'm assuming a work address here). That is, each employee has only one work address but each address can have many employees. So, to make this 1-M relationship work, the Employee record must reference the primary key on the Address table (i.e a Foreign Key). The primary key (PK) on the Address table can be (and probably should be) an auto-number field.
So consider this structure Code:
Employee Table EmpId - Primary Key AddressId - Foreign Key Department EmpName etc. Address Table AddressId - Primary key city state etc. SELECT whatever FROM Employee E LEFT JOIN Address A ON (E.AddressId = A.AddressId)
__________________
Wolffy ------------------------ Teaching people to fish. |
|
#3
|
|||
|
|||
|
Thanks buddy.Glad to get solution.I have one more question.
The Question is that I want to update two table with the help of store procedure thru id . E.G. I have list box in which empname and id is given.when i click on empname,all the relative data comes in textboxes from two tables. After that i want to edit the data which present in textboxes and update that data thru update query. Plz solve this...... Last edited by Shadow Wizard : May 9th, 2008 at 04:14 AM. Reason: removed signature |
|
#4
|
||||
|
||||
|
Fairly simple sproc. Because two tables are involved, you will need two update statements ; and because you have two update statements, you will need to use a BEGIN TRANSACTION and COMMIT TRANSACTION to ensure BOTH queries work. Give the spoc a go and if you get stuck, post what you have and we'll see if we can sort it.
|
|
#5
|
|||
|
|||
|
this is store procedure:
CREATE PROCEDURE update_procedure ( @updtid integer, @namee char(10), @organisation char(10), @adrs char(16), @area varchar(50), @landline numeric(9), @mob numeric(9), @cty char(10), @state char(10), @contry char(10) ) as update name set namee=@namee,organisation=@organisation,adrs=@adrs ,area=@area,landline=@landline,mob=@mob where nameid=@updtid declare @tempid integer set @tempid=(select nameid from name) print @tempid update city set cty=@cty,state=@state,contry=@contry where ctyid=@updtid GO I have List box in which list of all organisations listed.when click on the organisation ,textfields filled with data according to the org. and ID. I Store that id=@pdtid. when i update ,all the organisation showed repeatedly can say 2 times. Last edited by Shadow Wizard : May 9th, 2008 at 04:15 AM. Reason: removed signature |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Joining of two tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|