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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:39:43+00:00 2026-06-12T11:39:43+00:00

I have 2 tables: Appointments id serviceId 1 1 2 1 Services id 1

  • 0

I have 2 tables:

Appointments
id serviceId
1  1
2  1

Services
id
1

The appointments table is linked to the services table by use of the serviceId column. When retrieving data from the appointments table, i’d like to also retrieve the data from the services table, but the number of columns in each table does not match.

I’ve tried this:

SELECT appointments.*, services.* FROM appointments
INNER JOIN services ON id = appointments.serviceId
WHERE id = ?

But this does not work. First of all, in the join, how can I reference an ID from the appointments table that I have not even retrieved the data for yet? Second, how can I get all the data from both tables and then retrieve the data if the two column names match?

This won’t work:

results.getInt("id");

Because both tables have an id field.

  • 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-12T11:39:44+00:00Added an answer on June 12, 2026 at 11:39 am

    specify the tables name in which ID belongs,

    SELECT appointments.*, services.* 
    FROM appointments
         INNER JOIN services 
             ON Services.id = appointments.serviceId
    -- WHERE id = ? -- specify also here as the two tables have column ID
    

    or add ALIAS around them

    SELECT  appointments.id as AppID,
            appointments.serviceId as AppServiceID
            services.id AS ServiceID
    FROM    appointments
            INNER JOIN services
                ON Services.id = appointments.serviceId
    -- WHERE   id = ?
    

    when you get their values, use their alias now, something like this,

    results.getInt("AppID");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables linked by FK, I query on the first table using entity
I have two tables in my app: 'Clients' and 'Appointments' In the appointments table
I have two tables in my database that look like this CREATE TABLE IF
I have 2 hibernate entities/tables and need to combine information from both for use
I have a table the contains appointments. These appointments have different statuses (byte from
Table#Appointments: ID, Name, LocationID, Created Currently I have: SELECT * FROM Appointments WHERE Created
I have a table of Appointments and a table of AppointmentOutcomes. On my Appointments
So I have two tables. Table 1 is named 'appointment' with the following fields:
I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int

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.