If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > How do I reference a subquery again?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-11, 05:09
Helen Pippard Helen Pippard is offline
Registered User
 
Join Date: Dec 2011
Posts: 30
How do I reference a subquery again?

Hello

Is anyone able to help me with regards to referencing a subquery again?

My syntex is:

SELECT a.clrec_identity
, a.clmov_movedate
, (SELECT MAX(clmov_movedate)
FROM clinrec_movements
WHERE clmov_type In ('BO')
AND clmov_movedate < a.clmov_movedate
AND clrec_identity = ABC) Last_Date_Booked_Out
FROM clinrec_movements a
WHERE a.clrec_identity = ABC

Now I want to count how many clmov_movedates there are between
a.clmov_movedate and Last_Date_Booked_Out but am unsure how I can reference a subquery again? Would it be in the where clause?

I.e. WHERE a.clrec_identity = ABC
and a.clmov_movedate =
(select COUNT(clmov_movedate)
FROM clrec_movements
WHERE clrec_movedate BETWEEN a.clmov_movedate and Last_Date_Booked_Out) tracking_numbers?

Any help is greatly appreciated
Reply With Quote
  #2 (permalink)  
Old 12-12-11, 05:42
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
SELECT *
  FROM ( SELECT a.clrec_identity
              , a.clmov_movedate
              , ( SELECT MAX(clmov_movedate)
                    FROM clinrec_movements
                   WHERE clmov_type In ('BO')
                     AND clmov_movedate < a.clmov_movedate
                     AND clrec_identity = ABC ) Last_Date_Booked_Out 
           FROM clinrec_movements a
          WHERE a.clrec_identity = ABC ) x
 WHERE clmov_movedate =
       ( SELECT COUNT(clmov_movedate) 
           FROM clrec_movements
          WHERE clrec_movedate BETWEEN clmov_movedate 
                                   AND Last_Date_Booked_Out )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-12-11, 06:10
Helen Pippard Helen Pippard is offline
Registered User
 
Join Date: Dec 2011
Posts: 30
Hello

Thanks once again for your help

I have run the syntex and although it does not error, it does not show any values in the results.

I am getting the following error: Could not do a physical-order read to fetch next row. sqlerrm(clinrec_movements)




Do you know how I would also get the Count part to show as a column in the results also, as I am unsure where to name the count part of the query


Thanks
Helen
Reply With Quote
  #4 (permalink)  
Old 12-17-11, 03:05
begooden-it begooden-it is offline
Registered User
 
Join Date: Sep 2011
Location: Pont l'Abbé, Brittany, France
Posts: 183
Hi Helen,


you are probably hitting against a row or page lock.
To check this, run onstat -k and , if you know how to read it, try to identify
where the lock is.

Easier even: dbaccess sysmaster
select * from syslocks where tabname = "your table"

You should understand what is happening then

Hope this helps

Eric
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On