Appending query from the two more tables in the same sql

PeteEngineer
PeteEngineer used Ask the Experts™
on
I have a below sql which uses cursor, which will select a column from the tblMdMList  

DECLARE curMdMasterList CURSOR
   FOR SELECT MdID FROM tblMdMList
      WHERE MdDesc = 'Desc'
      
      
      i have two more tables tblMdMList2 and tblMdMList3 with the same table structures.
      
I want to append the results of the these two as like in tblMdMList into the same cursor

How to do this?

Something like....

DECLARE curMdMasterList CURSOR
   FOR SELECT MdID FROM tblMdMList and tblMdMList2 and tblMdMList3
      WHERE MdDesc = 'Desc'


Please help !
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
Hello PeteEngineer,

Presumably you mean:

DECLARE curMdMasterList CURSOR
   FOR SELECT MdID FROM tblMdMList
      WHERE MdDesc = 'Desc'
      UNION ALL
      SELECT MdID FROM tblMdMList2
      WHERE MdDesc = 'Desc'
      UNION ALL
      SELECT MdID FROM tblMdMList3
      WHERE MdDesc = 'Desc'



That said, you should avoid using cursors unless there really is no other way to do what you need to do...

Regards,

Patrick

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial