This topic is locked

display fields in list from more than one table

11/1/2006 4:25:35 PM
ASPRunnerPro General questions
I
intour author

Hi all,
I'm quite a newbie so please forgive me if this has been asked before.
I have an access database which is used for an online shop. The database contains several tables. I need to display data from more than one table in a single list - its just 2 extra fields from linked tables in the same database.
Asprunner only appears to let me display details from one table at a time.
Can I use it to do what I want?
many thanks

Sergey Kornilov admin 11/1/2006

Modify SQL query on Edit SQL query tab to select data from several tables.
Typical JOIN query looks like this:

select Cars.[ID],
[Make],
[Model],
[UserID],
UserName
From [Cars]
inner join users on cars.userid=users.id


More info and examples:

http://www.xlinesoft.com/asprunner/docs/us...sql_queries.htm

I
intour author 11/2/2006

Thanks for the relply. I have tried what you suggested but I am getting this message 'eroor in syntax 'From' clause. This isthe code - the last lines are the ones I have added:
select products.[idProduct],

[idSupplier],

[description],

[details],

[configOnly],

[serviceSpec],

[price],

[listPrice],

[bToBPrice],

[imageUrl],

[smallImageUrl],

[largeImageURL],

[sku],

[stock],

[listHidden],

[weight],

[deliveringTime],

[active],

[IdOptionGroupA],

[Arequired],

[IdOptionGroupB],

[Brequired],

[hotDeal],

[cost],

[visits],

[sales],

[emailText],

[stockLevelAlert],

[formQuantity],

[showInHome],

[removed],

[rndNum],

[priority],

[notax],

[noshipping],

[custom1],

[content1],

[custom2],

[content2],

[custom3],

[content3],

[xfield1],

[x1req],

[xfield2],

[x2req],

[xfield3],

[x3req],

[iRewardPoints],

[NoPrices],

[IDBrand],

[OverSizeSpec],

[sDesc],

[Downloadable],

[noStock],

[noshippingtext],

[pcprod_HideBTOPrice],

[pcprod_QtyValidate],

[pcprod_MinimumQty],

[pcprod_QtyToPound],

[pcprod_EnteredOn],

[pcprod_OrdInHome],

[pcprod_HideDefConfig],

[pcprod_Apparel],

[pcprod_ParentPrd],

[pcprod_Relationship],

[pcprod_ShowStockMsg],

[pcprod_StockMsg],

[pcprod_SizeLink],

[pcprod_SizeInfo],

[pcprod_SizeImg],

[pcprod_SizeURL],

[pcprod_StockAlarm],

[pcprod_AddPrice],

[pcprod_SentNotice],

[pcProd_SPInActive],

[pcprod_AddWPrice],

idCategory

From [products]

inner join products.idProduct = categories_products.idProduct

J
Jane 11/2/2006

Hi,
here is a correct From clause:

From [products]

inner join [categories_products]

on (products.idProduct = categories_products.idProduct)

I
intour author 11/2/2006

Hi Jane,
Thank you soooo much ! That worked perfectly.
Can I add another field from a 3rd table in the same database?
At the moment I have the main table 'products', and have now added another field from the table - 'categories_products'.
I would like to add one more field - categoryDesc - to the list from a 3rd table - 'categories' where the relationship is
categories_products.idcategory=categories.idCategory
The field idCategory is not present in the 'products' table
Nigel

J
Jane 11/2/2006

Hi,
sure, you can.

Here is a sample:

select products.[idProduct],

...

categories.categoryDesc

From [products]

inner join [categories_products] inner join [categories]

on ((products.idProduct = categories_products.idProduct) and (categories_products.idcategory=categories.idCategory))

I
intour author 11/2/2006

Thanks again jane for the quick response.
I'm getting syntax error in 'From' clause

select products.[idProduct],

..........

[pcProd_SPInActive],

[pcprod_AddWPrice],

idCategory,

categories.categoryDesc

From [products]

inner join [categories_products] inner join [categories]

on ((products.idProduct = categories_products.idProduct) and (categories_products.idCategory=categories.idCategory))


Is there anything you can see here?
I'm so grateful for your help on this - thank you.

J
Jane 11/3/2006

Sorry for my fault.

Here is the correct query:

select products.[idProduct],

..........

[pcProd_SPInActive],

[pcprod_AddWPrice],

idCategory,

categories.categoryDesc

From [categories]

inner join ([categories_products] inner join [products]

on (products.idProduct = categories_products.idProduct)) on(categories.idCategory=categories_products.idCategory)

I
intour author 11/3/2006

Hi Jane,
Many thanks for your reply and for giving your time.
I tried the latest code but now I'm getting a message that says:
'The specified field [detail] could refer to more than one table listed in the from clause of your sql statement.'
I do so appreciate your help with this !!
Nigel

J
Jane 11/3/2006

This error means that [detail] field is in more then one table.

You need to use these fields in the [TableName].[FieldName] format in your query.

I
intour author 11/3/2006

Hi Jane,
You are a star ! it worked !
Thank you so much for your help on this
x
Nigel