Results 1 to 7 of 7
  1. #1
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82

    Is there any way I can show that a record has a twin elsewhere?

    I have a list of songs on albums. In some cases the same song is on more than one album, and I'm wondering if there's a simple way to indicate that in a query? For example, by adding an asterisk.

    So, I have two tables:

    Code:
    Songs {
    songID (autonumber)
    title (text)
    }
    lp_contents {
    SongKeyID (autonumber), 
    song_id (number)
    LP_id (number)
    }
    To find all the songs on album #1076 I can query:

    Code:
    SELECT Songs.Title, LPContents.LP_id, LPContents.song_id
    FROM Songs INNER JOIN LPContents ON Songs.SongID = LPContents.song_id
    WHERE LPContents.LP_id=1076;
    LPContents can have multiple references to the same song, so in this list, songs 6 & 10 show up twice.

    Code:
    SongKeyID      song_id     LP_id
    1                    6              1076
    2                    6               20
    3                    7               1076
    4                    8               1076
    5                    9               20
    6                   10               1076
    7                   10               20

    Is there a way to put an asterisk next to any song_id that exists more than once in LPContents? So that a list of songs from album 1076 could display as:

    Code:
    Songs.Title    LPContents.song_id
    (*)song 1        6      
    song 2           7
    song 3           8
    (*)song 5        10
    Is such a thing possible within SQL? Or will I have to create a function so I can do something like:

    Code:
    SELECT IsDoubled(LPs.song_id), Songs.Title, LPContents.LP_id, LPContents.song_id
    FROM Songs INNER JOIN LPContents ON Songs.SongID = LPContents.song_id
    WHERE LPContents.LP_id=1076;


  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    I suggest you add a Boolean (yes/no) field to the LPContents table and call it Dupe or similar.
    Then create a duplicates query and set the Dupe field =true for all records identified using an update qery
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    An sql approach

    Code:
    SELECT songkeyid
    	,lp_id
    	,song_id
    FROM lpContent
    WHERE song_id IN (
    		SELECT song_id
    		FROM (
    			SELECT Count(LpContent.Song_ID) AS CountOfSongID
    				,LpContent.song_id
    			FROM LpContent
    			GROUP BY LpContent.song_id
    			HAVING (((Count(LpContent.Song_ID)) > 1))
    			)
    		);
    songkeyid lp_id song_id
    1 1076 6
    2 20 6
    6 1076 10
    7 20 10

  4. #4
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    To expand a bit on what was already posted, in order to get the preceding characters you want for those songs, you're going to need to add an IIf statement somewhere in the mix.

    If using Colin's approach with the Boolean field, then it might look like;

    SongTitle: IIf([Dupe]=True, "(*)" & [Title], [Title])

    If using the SQL approach like Orange suggested;

    SongTitle: IIf([CountOfSongID] > 1, "(*)" & [Title], [Title])

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I was only focusing on lpcontents.

    Here's modified sql to put the (*) beside the song_id

    Code:
    SELECT songkeyid, lp_id, "(*)" & song_id as DupSongIndicator
    FROM lpContent
    WHERE song_id IN (
            SELECT song_id
            FROM (
                SELECT Count(LpContent.Song_ID) AS CountOfSongID
                    ,LpContent.song_id
                FROM LpContent
                GROUP BY LpContent.song_id
                HAVING (((Count(LpContent.Song_ID)) > 1))
                )
            );
    songkeyid lp_id DupSongIndicator
    1 1076 (*)6
    2 20 (*)6
    6 1076 (*)10
    7 20 (*)10

  6. #6
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82
    Unfortunately my SQL is not good enough for me to figure out how to join the above query of LPContents with my own query of Songs + LPContents. How do I combine my own original query of

    Code:
    SELECT Songs.Title, LPContents.LP_id, LPContents.song_id
    FROM Songs INNER JOIN LPContents ON Songs.SongID = LPContents.song_id
    WHERE LPContents.LP_id=1076;
    with this one?
    Code:
    SELECT songkeyid, lp_id,song_id
    FROM lpContent
    WHERE song_id IN (
    SELECT song_id
    FROM (
    SELECT Count(LpContent.Song_ID) AS CountOfSongID, LpContent.song_id
    FROM LpContent
    GROUP BY LpContent.song_id
    HAVING (((Count(LpContent.Song_ID)) > 1))));

  7. #7
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    Try this;

    Code:
    SELECT IIf([DupeTitle]>1,"(*)" & [Title],[Title]) AS SongTitle, (Select Count(SongID) From LPContents Where Songs.SongID = LPContents.SongID) AS DupeTitle
    FROM Songs;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Show combobox only last and new record
    By civl_eng in forum Access
    Replies: 2
    Last Post: 05-01-2018, 11:18 AM
  2. Replies: 2
    Last Post: 04-19-2018, 03:51 PM
  3. Replies: 2
    Last Post: 03-14-2017, 02:48 AM
  4. How to show next available record number
    By gebmiller1984 in forum Forms
    Replies: 1
    Last Post: 02-04-2015, 01:23 PM
  5. Show same record once on the top
    By dmarques in forum Reports
    Replies: 2
    Last Post: 06-26-2012, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums