Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3782574
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:06:08+00:00 2026-05-19T11:06:08+00:00

Hopefully someone can help. I’m busy building a e-commerce website in dreamweaver. The website

  • 0

Hopefully someone can help. I’m busy building a e-commerce website in dreamweaver. The website will have have music cd’s, dvd’s, movies, and games for the moment. I have a database consisting of most of the above mention.

Now i have built all of it myself and am slowly learning as I go(I know a bit of code, SQL, PHP, etc.)

I have created a search bar which searches the database for whatever keyword was inserted and returns results on a new page. I thought i had created the ultimate piece of sql but one day i did a search of an album that had a track listing and it came up with repeats of this specific album as many times as there were songs on the album eg 10 songs=10 repeats of the album which to a user is not useful.

This is my code:

SELECT 
    Department.Dept, Artist.Artist, Catalogue.Title, Tracklisting.TrackTitle,
    Catalogue.ImagePath, Catalogue.Sell, Catalogue.ID
FROM Department 
INNER JOIN ((Artist INNER JOIN Catalogue ON Artist.ID =
Catalogue.Artist_ID) LEFT JOIN Tracklisting ON Catalogue.ID = Tracklisting.CatID) ON 
Department.ID = Catalogue.Department_ID

WHERE Department.Dept Like '$select' AND Artist.Artist='$search' OR Department.Dept
Like '$select' AND Artist.Artist Like '%$search' OR Department.Dept Like '$select' AND
Artist.Artist Like '$search%' OR Department.Dept Like '$select' AND Artist.Artist
Like '%$search%' OR Department.Dept Like '$select' AND Catalogue.Title='$search' OR
Department.Dept Like '$select' AND Catalogue.Title like '%$search' OR Department.Dept
Like '$select' AND Catalogue.Title like'$search%' OR Department.Dept Like '$select'
AND Catalogue.Title like'%$search%' OR Department.Dept Like '$select' AND
Tracklisting.TrackTitle='$search' OR Department.Dept Like '$select' AND
Tracklisting.TrackTitle like'%$search' OR Department.Dept Like '$select' AND
Tracklisting.TrackTitle like'$search%' OR Department.Dept Like '$select' AND
Tracklisting.TrackTitle like'%$search%'

This is an ODBC connection and all of these $search and $select are my php getting the info from the search bar and the department selection eg. music or games

There are 4 tables in database where i am pulling the info from. Artist – Catalogue – Tracklisting and Department. All 4 are linked and i have made the link between tracklisting and catalogue so if there is no tracklisting it still pulls the album info up
Ovblisly each album has multiple tracks so each track of the same album has the same id linked to the album that has a unique id and then linked to artist table where each artist has a unique id.

The query then gets displayed into a table in HTML in PHP so to get displayed over and over depending on if there are albums to get displayed repeatly but diffrent albums not the same as it does now with the traclisting.

I have searched high and low for answers and this morning i thought i had found it…GROUP BY

I have been unable to get group by to work and keep receiveing this error You tried to execute a query that does not include the specified expression ‘Dept’ as part of an aggregate function.

Is there a way to tell php to only display one item if it starts to repeat or does it need to go into sql with GROUP BY which i was using incorrectly.

I have found that if i remove the track listing from the sql query it is fixed but then no one will be ale to search by song. Maybe there is a way to create 2 different queries??

Any help will be much appreciated.

EDIT!

This was the final code that Larry answered for me which i am very gratefull for. Remous code may also work but i have to make it work

"SELECT Department.Dept, Artist.Artist, Catalogue.Title, Catalogue.ImagePath,
Catalogue.Sell, Catalogue.ID
FROM Department INNER JOIN (Artist INNER JOIN Catalogue ON Artist.ID =
Catalogue.Artist_ID) ON Department.ID = Catalogue.Department_ID 
WHERE Department.Dept Like '$select' AND (Artist.Artist Like '%$search%' OR    Catalogue.Title like'%$search%' OR Catalogue.ID IN (SELECT CatID
FROM TrackListing 
WHERE TrackTitle like'%$search%'))";

Many thanks to everyone that helped!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:06:08+00:00Added an answer on May 19, 2026 at 11:06 am

    First off, if you want to use GROUP BY then you must include every column you list in the SELECT in the GROUP BY:

     GROUP BY Department.Dept, Artist.Artist, Catalogue.Title, Tracklisting.TrackTitle,
         Catalogue.ImagePath, Catalogue.Sell, Catalogue.ID
    

    (you don’t list columns that are in an aggregate function like SUM or COUNT, but you’re not using any of those columns).

    But that isn’t going to solve your problem. I gather that even if you find track listings that match the search (which, please, must be escaped or parameterized to prevent SQL injection) then each track will be returned and GROUP BY won’t remove the records because the track name will make them unique.

    Instead, you need to remove tracklisting from the list of JOINed tables. Then you must remove references to the tracklisting columns from the SELECT and WHERE clauses.

    Finally, if you want to be able to search for albums that have tracks that contain the specified text, add an IN () subquery to your search.

    You’ll wind up with something like this:

     SELECT Department.Dept, Artist.Artist, Catalogue.Title,
         Catalogue.ImagePath, Catalogue.Sell, Catalogue.ID
     FROM Department INNER JOIN (Artist INNER JOIN 
          Catalogue ON Artist.ID = Catalogue.Artist_ID) 
          ON Department.ID = Catalogue.Department_ID
     WHERE Department.Dept Like '$select' AND (
            Artist.Artist Like '%$search%' OR
            Catalogue.Title like'%$search%' OR
            Catalog.ID IN (SELECT CatID FROM TrackListing WHERE TrackTitle like'%$search%'      )
           )
    

    Note that I remove a lot of apparent redundancy from your WHERE clause. If you’re searching, for instance, on Artist LIKE '%$search%' then you do not also need to do the other searches on Artist, you only need the broadest search. And you were repeating the Dept search for each other search (I assume you generated the query from Access’s query builder) but with proper parenthesization that’s not necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully someone can help here, it's incredibly frustrating! I have a couple of iOS
I have another beginner's question that hopefully someone can help with. I'm trying to
everyone! i have a question about sessions hopefully someone can help me with. I
Hopefully someone can help me with my problem. Background I have create an InfoPath
Hopefully someone can help, I have a challenging situation that I cannot not seem
Quite a simple one I think, but hopefully someone can help out. I have
hopefully someone can help me with this headache I have. I'm currently running Drupal
hopefully someone can help me with this odd problem. I have a database which
Hopefully someone can help me with a slight problem/confusion I have with Viewpagers and
Hopefully someone can help here. I have a ListView that is populated by a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.