954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

subtract to tables

pleaseeeeeeee hepl meeeeeeee!!!!!!!!!

i have 2 tables :
time1 (noo integer,days varchar,times varchar,Tindex integer,primary key
(noo,Tindex))

timetable1_1(COn integer,coursename varchar,dayss varchar,timess varchar,
primary key(COn))


i have created a new table temptime1 and tried to fill it with the rows in time1 which their days and times are not available in timetable1_1

i used the below query but it gives me error: "Operand should contain 1 column"


QUERY:

insert into TempTime1 (NOM,Tday,Ttime,Ttindex) select * from time1 where days and times not in (select * from timetable1_1)
katiiiii
Newbie Poster
5 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

INSERT INTO TempTime1 (NOM,Tday,Ttime,Ttindex) SELECT * FROM time1 WHERE days AND times NOT IN (SELECT * FROM timetable1_1)

Few things to note here

you are inserting values into 4 columns of TempTime1 table with
select * from time1
where time1 has more than 4 columns,so that's a error

and the second one : SELECT * FROM time1 WHERE days AND times NOT IN (SELECT * FROM timetable1_1)

you can't put 2 columns "days AND times" and say not in.......
and then you are trying to GET times which are not in timetable1_1
you have specify
select times from timetable1_1 as the inner query is returning more than 1 column


try this INSERT INTO TEMPTIME1
SELECT TOTAL.DAYS,TOTAL.TIMES,TOTAL.TINDEX FROM
(SELECT TIME1.DAYS,TIME1.TIMES,TIME1.TINDEX FROM
TIME1
LEFT OUTER JOIN TIMETABLE1_1
ON TIME1.TIMES=TIMETABLE1_1.TIMES
AND TIME1.DAYS=TIMETABLE1_1.DAYS
HAVING (TIMETABLE1_1.TIMES IS NULL AND TIMETABLE1_1.DAYS IS NULL)
)TOTAL

varmadba
Junior Poster in Training
83 posts since Jun 2008
Reputation Points: 22
Solved Threads: 9
 

yeah you are right . i was in a big mistake.
so i used the below query and it worked:

insert into TempTime1(Tday,Ttime) select days,times from time1  where days not in (select dayss1 from timetable1_1 ) union select days,times from time1  where times not in (select timess1 from timetable1_1 )
katiiiii
Newbie Poster
5 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

It's really simple...
all you have to do is replace inner * with your desired columns

The correct QUERY would be:
[code=sql]insert into TempTime1 (NOM,Tday,Ttime,Ttindex) select * from time1 where days and times not in (select days, times from timetable1_1)

QUERY:

insert into TempTime1 (NOM,Tday,Ttime,Ttindex) select * from time1 where days and times not in (select * from timetable1_1)


[/QUOTE]

rronyy
Newbie Poster
1 post since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You