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

  • Home
  • SEARCH
  • 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 8920087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:10:43+00:00 2026-06-15T06:10:43+00:00

im kinda new with mysql and i’m trying to create a kind complex database

  • 0

im kinda new with mysql and i’m trying to create a kind complex database and need some help.

My db structure

 Tables(columns)

 1.patients (Id,name,dob,etc....)
 2.visits (Id,doctor,clinic,Patient_id,etc....)
 3.prescription (Id,visit_id,drug_name,dose,tdi,etc....)
 4.payments (id,doctor_id,clinic_id,patient_id,amount,etc...) etc..

I have about 9 tables, all of them the primary key is ‘id’ and its set to autoinc.

i dont use relations in my db (cuz i dont know if it would be better or not ! and i never got really deep into mysql , so i just use php to run query’s to Fitch info from one table and use that to run another query to get more info/store etc..)

for example:
if i want to view all drugs i gave to one of my patients, for example his id is :100

1-click patient name (name link generated from (tbl:patients,column:id))
2-search tbl visits WHERE patient_id=='100' ; ---> that return all his visits ($x array)
3-loop prescription tbl searching for drugs with matching visit_id with $x (loop array).
4- return all rows found.

as my database expanding more and more (1k+ record in visit table) so 1 patient can have more than 40 visit that’s 40 loop into prescription table to get all his previous prescription.

so i came up with small teak where i edited my db so that patient_id and visit_id is a column in nearly all tables so i can skip step 2 and 3 into one step (
search prescription tbl WHERE patient_id=100), but that left me with so many duplicates in my db,and i feel its kinda stupid way to do it !!

should i start considering using relational database ?

if so can some one explain a bit how this will ease my life ?

can i do this redesign but altering current tables or i must recreate all tables ?

thank you very much

  • 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-06-15T06:10:44+00:00Added an answer on June 15, 2026 at 6:10 am

    Yes, you should exploit MySQL’s relational database capabilities. They will make your life much easier as this project scales up.

    Actually you’re already using them well. You’ve discovered that patients can have zero or more visits, for example. What you need to do now is learn to use JOIN queries to MySQL.

    Once you know how to use JOIN, you may want to declare some foreign keys and other database constraints. But your system will work OK without them.

    You have already decided to denormalize your database by including both patient_id and visit_id in nearly all tables. Denormalization is the adding of data that’s formally redundant to various tables. It’s usually done for performance reasons. This may or may not be a wise decision as your system scales up. But I think you can trust your instinct about the need for the denormalization you have chosen. Read up on “database normalization” to get some background.

    One little bit of advice: Don’t use columns named simply “id”. Name columns the same in every table. For example, use patients.patient_id, visits.patient_id, and so forth. This is because there are a bunch of automated software engineering tools that help you understand the relationships in your database. If your ID columns are named consistently these tools work better.

    So, here’s an example about how to do the steps numbered 2 and 3 in your question with a single JOIN query.

               SELECT p.patient_id p.name, v.visit_id, rx.drug_name, rx.drug_dose
                FROM patients     AS p
           LEFT JOIN visits       AS v    ON p.patient_id = v.patient_id
           LEFT JOIN prescription AS rx   ON v.visit_id = rx.visit_id
               WHERE p.patient_id = '100'
            ORDER BY p.patient_id, v.visit_id, rx.prescription_id
    

    Like all SQL queries, this returns a virtual table of rows and columns. In this case each row of your virtual table has patient, visit, and drug data. I used LEFT JOIN in this example. That means that a patient with no visits will have a row with NULL data in it. If you specify JOIN MySQL will omit those patients from the virtual table.

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

Sidebar

Related Questions

I am kinda new to database designing so i ask for some advices or
I'm new to mysql. Right now, I have this kind of structure in mysql
I'm kinda lost and need some help. In the past i have used php
I'm kinda new to Flex. I have trying to send Hash from Ruby on
I am kinda new to this Regex thing. When analyzing some code I frequently
I am kind of new to mySQL:s union functions, at least when doing inserts
I read some nice articles about how to connect to a remote MySQL database
MYSQL Database: I have a table of data that I need to put into
I'm kinda new to PDO with MYSQL, here are my two files: I have
I am kinda new to configuring a apache/mysql server , but I have 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.