Hi friends, In my project I'm using multiple tables to sotr the details.There is one main table and in the i'm storing the contact details of the family.And according to the number of members in the family I'm saving the member names and ages in different table.Now what I need is how can I retrive the details from multiple tables ? I know how to insert the details sp pls tell me that what concept i've to use for retrieving the details from different tables.If you have a sample code kindky post that also.I'll be very much useful for me... One more thing "kindly tell me whether my english is good enough to communicate with people without any fear of making mistakes".Thanks in advance :-)

Dani AI

Generated

For : the usual approach is to relate the main family row to the member rows by the common key (family_id) and then query across those tables. is correct to point toward JOINs — below are practical query patterns and a few common pitfalls that are often missing in short answers.

To get one row per family member (one row per person):

SELECT f.family_id, f.contact_name, m.member_id, m.name, m.age
FROM families AS f
JOIN family_members AS m
  ON f.family_id = m.family_id
WHERE f.family_id = :family_id;

To get one row per family with member names combined (useful for lists or CSV-style output):

SELECT f.family_id, f.contact_name,
  GROUP_CONCAT(CONCAT(m.name, ' (', m.age, ')') ORDER BY m.member_id SEPARATOR ', ') AS members
FROM families AS f
LEFT JOIN family_members AS m ON f.family_id = m.family_id
GROUP BY f.family_id, f.contact_name;

Practical notes and troubleshooting:

  • Prefer explicit column lists over SELECT * so results are predictable and smaller.
  • Ensure families.family_id is a PRIMARY KEY and family_members.family_id is indexed (and a FOREIGN KEY if desired) to keep JOINs fast.
  • Use prepared statements (placeholders like :family_id) in application code to prevent SQL injection.
  • Run EXPLAIN on complex queries to spot full-table scans and missing indexes.
  • Watch GROUP_CONCAT limits and modern SQL modes (ONLY_FULL_GROUP_BY) which affect GROUP BY behavior.

As already reassured, the original question is clear enough — the examples above cover the most common retrieval needs given the schema described.

Selecting data across multiple tables is done with a JOIN statement. There are several types of JOIN, the most basic is the INNER JOIN. This allows you to join two tables with a common set of columns. For example, if your main table has an ID field called family_id, and each member of the family is stored in another table that contains the family_id to indicate which family they belong to, then you can do this:

SELECT * FROM families
INNER JOIN family_members
ON families.family_id = family_members.family_id

There are millions of SQL examples on the web that can tell you how to join in other ways. Hope I have helped!

PS Your english is good, I understood what you were after so don't worry about it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.