Avatar of jtuttle99
jtuttle99

asked on 

Adding condition in SQL

Hello, Experts


I would like to add another table in the SQL and I don't know how to nest the join.
Here is the SQL


"SELECT Items.ImageID AS ImageID2,
Attribs.ImageID AS ImageID,
Priority,
Description,
Name
FROM Items LEFT JOIN Attribs ON Items.ImageID = Attribs.ImageID
WHERE ( Items.ImageID LIKE '%" + Replace(sidephoto_rs__MMColParam, "'", "''") + "%'
OR Name LIKE '%" + Replace(sidephoto_rs__MMColParam, "'", "''") + "%'  
OR  Description LIKE '%" + Replace(sidephoto_rs__MMColParam, "'", "''") + "%' )  
ORDER BY Priority, Items.ImageID ASC"


I would like to add this sentence in FROM clause

Attribs LEFT JOIN AttribList ON Attribs.Descriptor = AttribList.attribID

How do I do it?



ASPSQL

Avatar of undefined
Last Comment
jtuttle99
SOLUTION
Avatar of frankytee
frankytee
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jtuttle99
jtuttle99

ASKER

frankytee,
Thank you for your help.
I got syntax error trying your code.

I should explain the detail.
I would like to get ImageID in Items table
ImageID in Items table connect with ImageID in Attribs
Descriptor in Attribs table connect with attribID in Attriblist table

here is the table

Items-
ImageID, Priority, Description, Name

Attribs-
ImageID, Descriptor

AttribList-
AttribID, attribDesc

So I would like to include
attribDesc LIKE '%" + Replace(sidephoto_rs__MMColParam, "'", "''") + "%'  
in WHERE clause

and AttribID in AttribList is same as Descriptor in Attribs
 
So when I search keyword like "apple",
I would like search the word in Name, Description, ImageID(in Items table), and attribDesc(in Attriblist table) and get ImageID in Items table (not Attribs table)


ASKER CERTIFIED SOLUTION
Avatar of fhlio_admin
fhlio_admin
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of fhlio_admin
fhlio_admin
Flag of United States of America image

put quotes around it if needed... I don't know your surrounding code...
Avatar of jtuttle99
jtuttle99

ASKER

It seems to be working ,but I get same results.
How do I get rid of duplicates?

ex. if I search " apple", I get something like this as a results.

IMID-1002
IMID-1002
IMID-1002
IMID-1003
IMID-1003
IMID-1004

Avatar of jtuttle99
jtuttle99

ASKER

oh, never mind.

DISTINCT worked
ASP
ASP

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo