|
-
Jul 7th, 2006, 01:15 PM
#1
Thread Starter
Addicted Member
Nested SQL Query
I have a select statement to pull PICKSL, SLOT, PROD, DESC, PACK, MANU ID, HITIX, and PALLET QTY from the (PICKSL) table. The present nested select statement grabs all the records whose product numbers are NOT already in the ALTER table.
PROBLEM: I would like to pull the SLOT field from the TEST table since the PICKSL table does not have a SLOT field. Is there a way to do this in SQL? Thank you very much in advance.
VB Code:
sql = "INSERT INTO MAIN ( PICKSL, SLOT, PROD, [DESC], PACK, " & _
"[MANU ID], HITIX, [PALLET QTY] ) " & _
"SELECT p.PICKSL, p.PICKSL, p.PROD, p.DESC, p.PACK, " & _
"p.MANUID, p.HITI, p.OH " & _
"FROM PICKSL AS p " & _
"WHERE Not Exists ( " & _
"SELECT * " & _
"FROM [ALTER] a " & _
"WHERE a.PROD = p.PROD);"
Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.
-
Jul 7th, 2006, 02:51 PM
#2
Re: Nested SQL Query
 Originally Posted by manofsteel00
PROBLEM: I would like to pull the SLOT field from the TEST table since the PICKSL table does not have a SLOT field. Is there a way to do this in SQL?
If there's a link field between the Test table and the PickSL table you could use a Join.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jul 8th, 2006, 10:11 AM
#3
Re: Nested SQL Query
Nested queries are expensive and if you have some sort of a primary key that both tables 'know', you should use a JOIN. Also, why are you PICKing PICKSL twice? ( )
Code:
SELECT p.Picksl, p.Prod, p.Desc, p.Pack, p.Manuid, p.hiti, p.oh, t.Slot FROM
PICKSL P LEFT JOIN Alter A ON A.Prod = B.Prod
LEFT JOIN Test T ON P.SomeID = T.SomeID
WHERE B.Prod IS NULL
-
Jul 10th, 2006, 11:41 AM
#4
Thread Starter
Addicted Member
Re: Nested SQL Query
The PICKSL table does not have the SLOT field; it has everything but the slot field. I would like to create a query that pulls the SLOT field from the TEST table and the rest of the information from the PICKSL table to populate a listbox. My current query pulls all the information correctly except for the SLOT field, which is why I am currently just using the pick slot for the slot field.
Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.
-
Jul 10th, 2006, 02:02 PM
#5
Thread Starter
Addicted Member
Re: Nested SQL Query
The following code actually gives me the appropriate information EXCEPT if a product is not listed in the TEST table it will not be inserted to the MAIN table. In other words, there are some items that do not appear on the TEST table; therefore, their SLOT should be the same as their PICKSL. Would it just be better to loop through the database and set the SLOTs appropriately or is there a way I can retrieve all the records from the PICKSL table even though their SLOT is not on the TEST table? Please feel free to post any questions for clarity. Thank you in advance.
VB Code:
INSERT INTO MAIN ( PICKSL, SLOT, PROD, [DESC], PACK, [MANU ID], HITIX, [PALLET QTY] )
SELECT p.PICKSL, t.SLOT, p.PROD, p.DESC, p.PACK, p.MANUID, p.HITI, p.OH
FROM PICKSL AS p, TEST AS t
WHERE Not Exists (
SELECT *
FROM [ALTER] a
WHERE a.PROD = p.PROD)
AND t.PROD = p.PROD;
Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|