Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Syntax in SQL union
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

ngaisteve1
Junior Member

Malaysia
241 Posts

Posted - 26 October 2003 :  20:54:35  Show Profile  Send ngaisteve1 an ICQ Message
I think this question must be very simple for you guys but I just couldn't figure what wrong here.

sql = "Select * FROM maple WHERE type = '%"& strType &"%' UNION select * from asli WHERE type = '%"& strType &"%' order by date DESC "

Both maple and asli have type field.

Thanks.

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 26 October 2003 :  21:04:34  Show Profile
date is a reserved word for one.

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

ngaisteve1
Junior Member

Malaysia
241 Posts

Posted - 26 October 2003 :  22:11:56  Show Profile  Send ngaisteve1 an ICQ Message
Thanks Nikkol but I found nothing wrong with the date as I try using a normal sql statement (without union) and sort by date and it works.
Go to Top of Page

ngaisteve1
Junior Member

Malaysia
241 Posts

Posted - 26 October 2003 :  22:41:03  Show Profile  Send ngaisteve1 an ICQ Message
I think I got it. The problem is I should change = to LIKE because of the wildcard (%).
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 26 October 2003 :  23:50:00  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
You are correct about using LIKE instead of = since you are trying to find matching words but you should change the column named date because it is a reserved sql name

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

ngaisteve1
Junior Member

Malaysia
241 Posts

Posted - 27 October 2003 :  00:20:56  Show Profile  Send ngaisteve1 an ICQ Message
Actually, I didn't change the date field name but it actually create no problem.
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 27 October 2003 :  08:30:28  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Well then thats good, but you might experience problems later on because of it.

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 27 October 2003 :  09:06:21  Show Profile
The number of fields in both the select statements must match so be careful if adding columns at a later date, I would recommend you explicitely SELECT the required columns rather than using SELECT *

The UK MkIVs Forum
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.25 seconds. Powered By: Snitz Forums 2000 Version 3.4.07