Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

using select

2 posts in General Discussion Last posting was on 2003-01-09 21:53:08.0Z
Kevin Porsche Posted on 2003-01-06 20:15:44.0Z
Reply-To: "Kevin Porsche" <store@shady-maple.com>
From: "Kevin Porsche" <store@shady-maple.com>
Subject: using select
Date: Mon, 6 Jan 2003 15:15:44 -0500
Lines: 1042
Organization: Shady Maple Farm Market, Inc.
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <4Ut5nKctCHA.199@forums.sybase.com>
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: hci215104.hydrosoft.net 65.166.215.104
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub ianywhere.public.general:347
Article PK: 2169

SELECT * FROM "DBA"."mvmt_history" cross join item;
select item_number, dept_code, item_long_desc, commodity_code,
inv_on_hand_qty from item
where commodity_code > '500' order by item_number
select mvmt_start_time from mvmt_history

How do i select 2 different fields from 2 different tables? Everything
works up to the last line. I'm using sybase adaptive server anywhere isql
verson 7.

Thanks

clip_image002.jpg

Raymond_Kwong Posted on 2003-01-09 21:53:08.0Z
From: Raymond_Kwong
Date: Thu, 9 Jan 2003 16:53:08 -0500
Newsgroups: ianywhere.public.general
Subject: Re: using select
Message-ID: <98FAB63A8CDA9276007838C085256CA9.007300BF85256CA6@webforums>
References: <4Ut5nKctCHA.199@forums.sybase.com>
Lines: 42
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub ianywhere.public.general:333
Article PK: 2147

You posted the following:

SELECT * FROM "DBA"."mvmt_history" cross join item;
select item_number, dept_code, item_long_desc, commodity_code,
inv_on_hand_qty from item
where commodity_code > '500' order by item_number
select mvmt_start_time from mvmt_history

How do i select 2 different fields from 2 different tables? Everything
works up to the last line. I'm using sybase adaptive server anywhere isql
verson 7.




Well the last line said:

select mvmt_start_time from mvmt_history

If mvmt_history is a table, why would you experience an error caused by
selecting 2 different fields from 2 different tables?

If it is a view, I would have expected an error when you create the view
anyways.

If I take a leap of faith and assume that your DML statements are actually
interpreted in reverse such that the cross join statement is the one you're
asking, then the general answer of selecting 2 different fields from two
different tables is as follows:

Instead of using the *, use specify the column names. To distinguish
columns with the same name from two different tables you can use the
tablename.columnname format.

So if both mvmt_history and item have a column called id, to obtain the
value of the id column in the mvmt_history field you'd have. eg.

SELECT mvmt_history.id FROM "DBA"."mvmt_history" cross join item

You can also use aliases to distinguish columns in a result set. eg.

SELECT mvmt_history.id AS historyid, item.id AS itemid FROM
"DBA"."mvmt_history" cross join item