Author |
Topic |
Pantso
Starting Member
4 Posts |
Posted - 2010-06-09 : 08:54:24
|
Hi allI am new to SQL and i would to know if anyone can help me work around this problem:i have 2 tablestable1 (id: integer, name: string, surname: string, department: integer)table 2 (id: integer, desciption: String)where table1.department is related to table2.idI want to make a statement in order my user to be able to insert values in table1 but given the following ('Tom', 'Jones', 'Music')so it can go and retrive the number that correspond to 'Music' from table2 and put it on table11. Excuse my english2. Thanx in advance |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-06-09 : 09:06:13
|
Here your query.insert into table1 (name,surname,department)Select 'Tom', 'Jones',(select id from table2 where desciption='Music') as dept_idSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-06-09 : 09:07:41
|
select tab1.name, tab1.surname, tab2.descriptionfrom table1 tab1inner join table2 tab2on tab2.id = tab1.departmentwhere tab2.description like '%Music%' |
|
|
Pantso
Starting Member
4 Posts |
Posted - 2010-06-09 : 09:31:21
|
first of all Thanx to you (senthil_nagore and RickD) both but i think i didnt write my question very good or i cannot understand very good what you answeredso this is what i was tryingi would make it more understanding by explainng without the true columnsi havetable1 (column1, column2, column3, column4) where column1 = integer - auto increment, clumn2 = text, column3 = text , column 4 = integerandtable2 (column1 , column2) where column1 = integer - auto increment and column2 = textNow table1.column4 is related to table2.column1 thats table1.column4 = table2.column1what i was trying is to be have an SQL statement that can insert values that are not fixed maybe different every timebut i want them to be added into table1 and given for example ('Tom', 'Jones', 'Music')where 'Tom' corresponds to tale1.column2 , 'Jones' corresponds to table1.column3 but 'Music' correspond to table2.column2 and i want to add the corresponding integer of that description that is the table2.column1 I have tried the following but i know its wrong maybe it helpsselect table1.column2,table1.column3,table2.column2 from table1, table2(INSERT INTO table1 (column2,column3, column4) VALUES ('Tom', 'Jones', 'Music'))where table1.column4=table2.column1thanx again |
|
|
Pantso
Starting Member
4 Posts |
Posted - 2010-06-09 : 09:36:47
|
quote: Originally posted by RickD select tab1.name, tab1.surname, tab2.descriptionfrom table1 tab1inner join table2 tab2on tab2.id = tab1.departmentwhere tab2.description like '%Music%'
thanx but i think i didnt write the question right please see the previous post |
|
|
Pantso
Starting Member
4 Posts |
Posted - 2010-06-09 : 09:37:49
|
quote: Originally posted by senthil_nagore Here your query.insert into table1 (name,surname,department)Select 'Tom', 'Jones',(select id from table2 where desciption='Music') as dept_idSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
thanx but i think i didnt write the question right please see the previous post |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-06-10 : 04:22:02
|
insert into table1select 'tom', 'jones', table2.idfrom table1 tab1inner join table2 tab2on tab2.id = tab1.departmentwhere tab2.description like '%Music%' |
|
|
Noor Anwar
Starting Member
8 Posts |
Posted - 2010-07-24 : 04:30:49
|
Respected Sir,I'm not sure if this is posted in the correct forum topic area. I'm just looking for some general advice. I have an desktop application(whole hospital opd and indoor patient record) that uses SQL 2005 and Visual Basic .Net,many of tables are used a lot(store and retrieve data from same table from multiple clients) how should i implement the indices that insertion and retrieval of data may not suffer.(speed slow)my another questioni heared that if index is applied on a table then retrival of data is so much fast but insertion take longer? and another questionif a table has primary key (is primary key auto indexed)andif a table has foriegn key relationship. Are foreign key tables are auto indexed or manually have to index the foreign key tables.and how i can properly index this database that no future slowness problems occure with respect to retrival and insertion of records.Sir i am searching that no future problems occur.(That of speed slow problem at storing time that was in sql server 2000 i experienced only at 70,000 records system cooled down)Please feel free to share your methods with me so I can go away and research it. Thank you in advance!Signature |
|
|
|