|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
SQL help
I have the following 2 sql strings:
strsql = "SELECT * FROM [tbl_officer_info] WHERE [active_indr]=-1" strsql = "SELECT * FROM [tbl_other_received] WHERE [active_indr]=-1" I wish to have them combined so that they take in from bot tables at once and then order by first_name & last_name... ~ ![]() |
|
#2
|
||||
|
||||
|
SELECT * FROM [tbl_officer_info] WHERE [active_indr]=-1
UNION ALL SELECT * FROM [tbl_other_received] WHERE [active_indr]=-1 ORDER BY [first name], [last name] rudy |
|
#3
|
||||
|
||||
|
that doesn't work as the 2 tables have different structures, here is the answer:
strsql = "SELECT tbl_officer_info.id, tbl_officer_info.first_name, tbl_officer_info.last_name FROM tbl_officer_info UNION ALL SELECT tbl_other_received.id, tbl_other_received.first_name, tbl_other_received.last_name FROM tbl_other_received WHERE active_indr=-1 ORDER BY last_name, first_name;" ![]() |
|
#4
|
||||
|
||||
|
yeah, UNION [ALL] requires the same structure in both SELECT lists
now you know ![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > SQL help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|