473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SELECT statement

Oli
Hi

In my company one of the people who works for me has done this:

sqlText = "SELECT products.ProdID, productName, " _
& "productPrice, quantity from products, " _
& "itemsOrdered where " _
& "products.productID = itemsOrdered.productID "_
& "and itemsOrdered.orderID = " & intOrderID

I am just a little unsure what products.ProdID means when later on in the
string there is the FROM products?

Anyone tell me?

THanks
Oli
Jul 19 '05 #1
6 1408
Jos
Oli wrote:
Hi

In my company one of the people who works for me has done this:

sqlText = "SELECT products.ProdID, productName, " _
& "productPrice, quantity from products, " _
& "itemsOrdered where " _
& "products.productID = itemsOrdered.productID "_
& "and itemsOrdered.orderID = " & intOrderID

I am just a little unsure what products.ProdID means when later on in
the string there is the FROM products?

Anyone tell me?

THanks
Oli


This is just the most extensive way of writing the command.
In your particular case, you are allowed to drop all the "products."
prefixes.
They are only needed when you are querying more than one table
(just for the case where 2 tables would have a column with the
same name).

--

Jos
Jul 19 '05 #2
Oli *is* selecting from two tables, and *should* prefix all column names
with table names to make things clear and unambiguous (both for the software
and for a developer viewing the code). I also suggest using an
ANSI-standard INNER JOIN syntax rather than this shorthand implicit join.
This way, you can separate the join clause(s) from the where clause(s),
making the relationship(s) easier to understand, and the code easier to
maintain. You can shorten things by using aliases for the table names, and
you can also keep the "short name" for each column, e.g.

SELECT
ProductId = p.ProductID,
productName = p.produectName,
productPrice = p.produectPrice,
quantity = i.quantity
FROM
Products p
INNER JOIN
itemsOrdered i
ON p.productID = i.productID
WHERE
...

(Also, is your column named prodID or productID? And why do the productName
and productPrice columns need the word "product" in their name? Isn't that
implied, since they're already in the products table?)

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Jos" <jo***************@fastmail.fm> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...
Oli wrote:
Hi

In my company one of the people who works for me has done this:

sqlText = "SELECT products.ProdID, productName, " _
& "productPrice, quantity from products, " _
& "itemsOrdered where " _
& "products.productID = itemsOrdered.productID "_
& "and itemsOrdered.orderID = " & intOrderID

I am just a little unsure what products.ProdID means when later on in
the string there is the FROM products?

Anyone tell me?

THanks
Oli


This is just the most extensive way of writing the command.
In your particular case, you are allowed to drop all the "products."
prefixes.
They are only needed when you are querying more than one table
(just for the case where 2 tables would have a column with the
same name).

--

Jos

Jul 19 '05 #3
TJS
products.ProdID is reference to the field name ProdID in the products table
products is the table name
"Oli" <ol*@NOSPAMoliwoods.co.uk> wrote in message
news:c3**********@sparta.btinternet.com...
Hi

In my company one of the people who works for me has done this:

sqlText = "SELECT products.ProdID, productName, " _
& "productPrice, quantity from products, " _
& "itemsOrdered where " _
& "products.productID = itemsOrdered.productID "_
& "and itemsOrdered.orderID = " & intOrderID

I am just a little unsure what products.ProdID means when later on in the
string there is the FROM products?

Anyone tell me?

THanks
Oli

Jul 19 '05 #4
Isn't Name a reserved word? Thus productName

"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
Oli *is* selecting from two tables, and *should* prefix all column names
with table names to make things clear and unambiguous (both for the software and for a developer viewing the code). I also suggest using an
ANSI-standard INNER JOIN syntax rather than this shorthand implicit join.
This way, you can separate the join clause(s) from the where clause(s),
making the relationship(s) easier to understand, and the code easier to
maintain. You can shorten things by using aliases for the table names, and you can also keep the "short name" for each column, e.g.

SELECT
ProductId = p.ProductID,
productName = p.produectName,
productPrice = p.produectPrice,
quantity = i.quantity
FROM
Products p
INNER JOIN
itemsOrdered i
ON p.productID = i.productID
WHERE
...

(Also, is your column named prodID or productID? And why do the productName and productPrice columns need the word "product" in their name? Isn't that implied, since they're already in the products table?)

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Jos" <jo***************@fastmail.fm> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...
Oli wrote:
Hi

In my company one of the people who works for me has done this:

sqlText = "SELECT products.ProdID, productName, " _
& "productPrice, quantity from products, " _
& "itemsOrdered where " _
& "products.productID = itemsOrdered.productID "_
& "and itemsOrdered.orderID = " & intOrderID

I am just a little unsure what products.ProdID means when later on in
the string there is the FROM products?

Anyone tell me?

THanks
Oli


This is just the most extensive way of writing the command.
In your particular case, you are allowed to drop all the "products."
prefixes.
They are only needed when you are querying more than one table
(just for the case where 2 tables would have a column with the
same name).

--

Jos


Jul 19 '05 #5
> Isn't Name a reserved word? Thus productName

It should be avoided, but it's legal syntax and will work as it is...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #6
Oli
Ahhh, I think I get you now!
THanks
"Oli" <ol*@NOSPAMoliwoods.co.uk> wrote in message
news:c3**********@sparta.btinternet.com...
Hi

In my company one of the people who works for me has done this:

sqlText = "SELECT products.ProdID, productName, " _
& "productPrice, quantity from products, " _
& "itemsOrdered where " _
& "products.productID = itemsOrdered.productID "_
& "and itemsOrdered.orderID = " & intOrderID

I am just a little unsure what products.ProdID means when later on in the
string there is the FROM products?

Anyone tell me?

THanks
Oli

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
3
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int...
4
by: 001 | last post by:
Hello, The select statement needs only 1 second to complete the query. But the update statement spends 30 minutes. Why? SELECT STATEMENT: declare @IDate smalldatetime select @IDate=col001...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
6
by: Bob Stearns | last post by:
I am getting duplicate rows back from a select distinct statement of the form: SELECT DISTINCT 'jhough', '000111', t0.bhid FROM (SELECT lots of good stuff) t0 LEFT OUTER JOIN another_table ...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
0
FishVal
by: FishVal | last post by:
Hereby I'm proposing a way of convinient work with properties containing SQL Select statements, particulary RowSource property of ComboBox and ListBox. The usual way is the following. Private...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.