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 4331078
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:03:23+00:00 2026-05-21T10:03:23+00:00

I’m working on a application that needs to store a deck of hands in

  • 0

I’m working on a application that needs to store a deck of hands in database. I’m not sure whats is the best way to represent this in a database.

The deck will be pre-dealt to 4 hands with each holding 13 cards by the application. After that I need to store the hands and additional data like suit distribution etc…

Is it best to create a seperate row for each hand and associate it with a deck? Or maybe it would be better to keep them in one row?

Also I’m not sure if I should keep them as text or number.
Here’s an example:

Sorted by suit and separated by dot
AK.32.6543.AKQ98

Or

(52 = Largest rank or largest suit or 02 = 2 of smallest suit)
405251282717161514012322200908

Any ideas?

PS: There is a reason to store the cards. We need to analyze the hand distributions, high card points etc…

  • 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-21T10:03:23+00:00Added an answer on May 21, 2026 at 10:03 am

    I’d think the most natural thing would be to create a table for cards, that would have one record for each card in the deck, and then a record for hands, that would have one record for each card in the hand. If there’s data about the hand as a whole — the name of the player? where he’s sitting at the table? how many chips he has? whatever — then you’d need a separate table for the hand as opposed to the cards in the hand. I’d also create a lookup table for suits.

    (We could debate use of synthetic keys versus natural keys here, but that’s another subject.)

    card (cardid, suitid, rank)
    suit (suitid, suitname)
    hand (handid, playername, whatever)
    handcard (handcardid, handid, cardid)
    

    My first impulse would be to make “rank” a number from 1 to 13, and translate 1 to “Ace” and 11 to 13 to “Jack”, “Queen”, and “King” at output time. You could store them as text, but then it would be difficult to compare ranks, if there is some need to do that. i.e. deciding if 13>10 is easy for the database; King>10, not so much.

    I definitely would NOT try to cram identification of multiplpe cards into a single field, whether separated by periods or fixed length ids or whatever. Doing that would require your program to have code to take this field apart to get the data you want, instead of just letting the database retrieve the data you want, which is what databases are for.

    I don’t know what you want to do with these card hands, but most things you would be likely to want to do are pretty easy with a structure like I’m describing, fairly tough if you cram a list of cards into a single field. Like, “Who has the King of Spades?” Easy:

    select playername
    from hand
    join handcard using (handid)
    join card using (cardid)
    join suit using (suitid)
    where suit.name='Spades' and card.rank=13
    

    Or, “How many face cards does each player have?”

    select playername, count(*)
    from hand
    join handcard using (handid)
    join card using (cardid)
    where card.rank between 11 and 13
    

    Of course “What cards does player #3 have?” is also easy:

    select rank, suitname
    from handcard
    join card using (cardid)
    join suit using (suitid)
    where handid=3
    

    Doing those queries with a packed format would require tricky string extraction calls. And string manipulation is always a pain. Like you always run into problems like, if I’m searching for 2’s in text, how do I exclude the 2’s that are part of ’12’s? etc.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have a reasonable size flat file database of text documents mostly saved in

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.