Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL table question?

  • 25-03-2015 1:49pm
    #1
    Registered Users, Registered Users 2 Posts: 2,640 ✭✭✭


    Hi guys. I'm trying to put together a simple beer locator, along the lines of the beer finder app/map from beior.ie. ( I have e-mailed them to let them know I'm doing this, it's not for commercial gain:))

    Im having a little trouble with my database.
    I have a table for beers: (ID, brewery, name, type, abv, price, country).
    and one for bars:(ID, name, address, lat, lang)

    I want each bar to have a selection of beers available, but i'm having trouble doing this. I had initially intended to have a column called "available beers" in the "bars" table, but seeing as each bar will obviously have more than one beer available this won't work as it will break the rule that cells should be atomic.

    Im thinking I may have to do a table of bars vs beers?????


Comments

  • Registered Users, Registered Users 2 Posts: 10,805 ✭✭✭✭28064212


    RINO87 wrote: »
    Im thinking I may have to do a table of bars vs beers?????
    This. It's a many-to-many relationship i.e. one bar can have multiple beers, and one beer can be in multiple bars. So you need a junction table

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 306 ✭✭yes there


    A really simple way would be to create a table beerLists, put it's beer list ID as a value in your available beers column.Each beer list ID can have multiple beerIDs.


  • Registered Users, Registered Users 2 Posts: 2,640 ✭✭✭RINO87


    Thanks for the input folks!


  • Registered Users, Registered Users 2 Posts: 4,468 ✭✭✭CruelCoin


    Have a boolean table maybe?

    Bar1
    beer1 (true/false), beer2(true/false), etc.

    Bar2
    beer1 (true/false), beer2(true/false), etc.

    And so on.


  • Registered Users, Registered Users 2 Posts: 2,640 ✭✭✭RINO87


    CruelCoin wrote: »
    Have a boolean table maybe?

    Bar1
    beer1 (true/false), beer2(true/false), etc.

    Bar2
    beer1 (true/false), beer2(true/false), etc.

    And so on.

    Yeah I had though about going along those lines, however Im hoping to work with 70 beers and 30 bars. It could get messy


  • Advertisement
  • Registered Users Posts: 306 ✭✭yes there


    You could also just annotate that column with a manyToOne bi directional relationship when you implement it in software when making your entity classes depending on your ORM. I know that would work if you are using Hibernate.


  • Registered Users, Registered Users 2 Posts: 1,757 ✭✭✭Deliverance XXV


    Keep it simple and easy to manage.

    Beers
    ID, brewery, name, type, abv, country

    Bars
    ID, name, address, lat, lang

    Stock
    ID, barID, beerID, price

    So one bar would have multiple entries of their different beers in the stock table:

    Stock Example Data
    1, 12, 34, 4.00
    2, 12, 14, 4.00
    3, 12, 10, 4.00
    4, 12, 6, 4.00
    5, 12, 21, 4.00
    ...

    This will make queries much easier. You can query for the cheapest beer with the ID 34 in the stock table, etc.


  • Registered Users, Registered Users 2 Posts: 2,640 ✭✭✭RINO87


    That's perfect, simple really when you see it but the ideas still don't come to me immediately. Thanks folks.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    +1 Deliverance XXV but you also need the following tables (normalise)
    Brewery
    BreweryID, Name,TypeID,abvID, CountryId

    BeerType
    TypeID, Beer

    ABV
    ABVid,ABV

    Country
    CountryID, Country

    Beers
    ID, BreweryID, name, typeID, abvID, countryID


  • Registered Users, Registered Users 2 Posts: 40,513 ✭✭✭✭ohnonotgmail


    amen wrote: »
    +1 Deliverance XXV but you also need the following tables (normalise)
    Brewery
    BreweryID, Name,TypeID,abvID, CountryId

    BeerType
    TypeID, Beer

    ABV
    ABVid,ABV

    Country
    CountryID, Country

    Beers
    ID, BreweryID, name, typeID, abvID, countryID

    why would you need a table for the ABV? Surely thats just a number?


  • Advertisement
  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    CruelCoin wrote: »
    Have a boolean table maybe?

    Bar1
    beer1 (true/false), beer2(true/false), etc.

    Bar2
    beer1 (true/false), beer2(true/false), etc.

    And so on.
    You go sit in the corner for that.


  • Registered Users, Registered Users 2 Posts: 40,513 ✭✭✭✭ohnonotgmail


    You go sit in the corner for that.

    I've seen worse.


  • Registered Users, Registered Users 2 Posts: 586 ✭✭✭Aswerty


    I've seen worse.

    Bar1
    beer1 ('yes'/'no'), beer2('yes'/'no'), etc.

    Bar2
    beer1 ('yes'/'no'), beer2('yes'/'no'), etc.

    :pac:


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    hmm I suppose if abv is only a number then you could leave it
    for some reason I had text in mind


Advertisement