473,563 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT statement

Oli
Hi

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

sqlText = "SELECT products.ProdID , productName, " _
& "productPri ce, quantity from products, " _
& "itemsOrder ed where " _
& "products.produ ctID = itemsOrdered.pr oductID "_
& "and itemsOrdered.or derID = " & 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 1422
Jos
Oli wrote:
Hi

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

sqlText = "SELECT products.ProdID , productName, " _
& "productPri ce, quantity from products, " _
& "itemsOrder ed where " _
& "products.produ ctID = itemsOrdered.pr oductID "_
& "and itemsOrdered.or derID = " & 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******** ******@TK2MSFTN GP09.phx.gbl...
Oli wrote:
Hi

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

sqlText = "SELECT products.ProdID , productName, " _
& "productPri ce, quantity from products, " _
& "itemsOrder ed where " _
& "products.produ ctID = itemsOrdered.pr oductID "_
& "and itemsOrdered.or derID = " & 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*@NOSPAMoliw oods.co.uk> wrote in message
news:c3******** **@sparta.btint ernet.com...
Hi

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

sqlText = "SELECT products.ProdID , productName, " _
& "productPri ce, quantity from products, " _
& "itemsOrder ed where " _
& "products.produ ctID = itemsOrdered.pr oductID "_
& "and itemsOrdered.or derID = " & 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***@TRASHasp faq.com> wrote in message
news:Oo******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP09.phx.gbl...
Oli wrote:
Hi

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

sqlText = "SELECT products.ProdID , productName, " _
& "productPri ce, quantity from products, " _
& "itemsOrder ed where " _
& "products.produ ctID = itemsOrdered.pr oductID "_
& "and itemsOrdered.or derID = " & 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*@NOSPAMoliw oods.co.uk> wrote in message
news:c3******** **@sparta.btint ernet.com...
Hi

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

sqlText = "SELECT products.ProdID , productName, " _
& "productPri ce, quantity from products, " _
& "itemsOrder ed where " _
& "products.produ ctID = itemsOrdered.pr oductID "_
& "and itemsOrdered.or derID = " & 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
5226
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 works as expected. But >>> numb=10 >>> cursor.execute("SELECT * FROM mytest where clientID = %d",numb) Traceback (innermost last): File...
0
10179
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 database table, using dynamic sql. Executing 'EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;' the error code -2149 is returned That means...
3
5715
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 pointing to the sentence they come from (a column called "regret"). I also have a table of stop words (called "GenericStopWords") that contains the words I...
4
2238
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 from USDay select * from USDay A
3
6436
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too...
1
3654
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 "access_log", the referential integrity triggers generate these queries: SELECT 1 FROM ONLY "public"."application_type" x
6
13751
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 t1 ON relevant_stuff WHERE (lots of conditions) After re-reading the relevant pat ofVol 1 of the SQL Reference I am unablee to see how this is...
19
8353
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 FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. ...
1
21652
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 "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan" case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb" End Select
0
5616
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 Sub Combo1_AfterUpdate() Me.Combo2.RowSource = "SELECT ... FROM ... WHERE Table2.keyID=" & Me.Combo1 & ";" Combo2.Requery
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.