0

I have 2 tables in SQLite. One is called contacts and the other is phoneNumbers. phoneNumbers is linked to contacts with integer references. Here is the tables:

CREATE TABLE contacts(
    id INTEGER PRIMARY KEY,
    name text
);

CREATE TABLE phoneNumbers(
    id INTEGER PRIMARY KEY,
    homePhone text,
    contact_id INTEGER REFERENCES contacts(id)
);

My question is, how can I access all homePhone that is linked to contacts (id) 1?

Hope this is clear. If you have any questions, feel free to ask in the comments.

Phil
  • 157,677
  • 23
  • 242
  • 245

1 Answers1

0

Here you have it:

SELECT homePhone 
FROM phoneNumbers 
JOIN contacts
ON homePhone.contact_id=contacts.id
WHERE contacts.id=1 

And never use SELECT * : https://stackoverflow.com/a/3639964/1919749

Community
  • 1
  • 1
ismaestro
  • 7,561
  • 8
  • 37
  • 50