Results 1 to 4 of 4

Thread: Sqlite question: group by column with multiple tags?

  1. #1
    Join Date
    Oct 2006
    Location
    Argentina
    Beans
    584
    Distro
    Ubuntu

    Sqlite question: group by column with multiple tags?

    Suppose that have 2 columns: folders and tags:
    Code:
    ~/Music|classic,rock
    ~/Music|classic,rock
    ~/Pictures|art,photos
    ~/Pictures|art,photos
    ~/Pictures|art,photos
    To know the folder count I do:
    Code:
    sqlite3 test.db  "select folder, count(folders) from t1 group by folder"
    Returns:
    Code:
    ~/Music|2
    ~/Pictures|3
    How can I do the same for tags using only sqlite to get this:
    Code:
    art|3
    classic|2
    photos|3
    rock|2
    Another question, is there any way to get max count for all grouped columns in one single consult?
    It should return something like this:
    Code:
    2|4
    Meaning that the first column has 2 unique values (~/Music and ~/Pictures) and the second column has 4 (art, classic. photos and rock)

    Many thanks in advance!

  2. #2
    Join Date
    Oct 2006
    Location
    Argentina
    Beans
    584
    Distro
    Ubuntu

    Re: Sqlite question: group by column with multiple tags?

    Maybe if I ask in a different way: What is the standard way of storing and counting tags with sqlite?

  3. #3
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,703

    Re: Sqlite question: group by column with multiple tags?

    I would not put multiple tags in one column. If it were arranged more like this:

    Code:
    ~/Music|classic
    ~/Music|rock
    ~/Pictures|art
    ~/Pictures|photos
    then you can do things like:
    Code:
    select folder, count(*) from t1 group by folder
    select tag, count(*) as numfolders from t1 group by tag order by numfolders limit 1
    The "limit 1" is mysql's way of getting just the first line. I don't know what the equivalent syntax for sqlite is.
    I don't know how to get both maxes at once.

  4. #4
    Join Date
    Oct 2006
    Location
    Argentina
    Beans
    584
    Distro
    Ubuntu

    Re: Sqlite question: group by column with multiple tags?

    Thanks for the answer.
    Quote Originally Posted by The Cog View Post
    I would not put multiple tags in one column.
    Yes it seems that that is the way to do it, I have also asked here and I got the same answer.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •