Question Locked

SQlite

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need help with a sqlite query, i pulled my phonebook from my Iphone and opened it with SQLite database broswer, now I need a string to query the DB, I need to view the names and numbers anyone got a SQL string for this as I in't got a clue

Update
table abperson (This table holds the names)
table abmultivalue (This table holds the numbers)

So what I want to do is query the DB to show both the names and numbers on one sheet make sence?

4 replies

by shellbot

Ok, never used SQLLite, so presuming its pretty much the same as SQL regular.

Lets assume:
abperson - has columns called personid, firstname, lastname
and
abmultivalue - has columns called personid, phone number

(each table needs a column that matches to the other table (relation), reasoning says its
called something like personid, or contactid or something like that)

either of these 2 queries should work..I presume SQLLite allows joins.
You'll need to change your column names to suit what you have.
This will give you mor info than you need, but will show you how it works.

select p.personid, p.firstname, p.lastname, m.personid, m.phonenumber
from abperson p,abmultivalue m
where p.personid = m.personid

select p.personid, p.firstname, p.lastname, m.personid, m.phonenumber
from abperson p
inner join abmultivalue m
on p.personid = m.personid

Once you understand what I've done above, this is what you'll want:

select p.firstname, p.lastname, m.phonenumber
from abperson p
inner join abmultivalue m
on p.personid = m.personid

or

select (p.firstname + ' ' + p.lastname) as Name, m.phonenumber
from abperson p
inner join abmultivalue m
on p.personid = m.personid

or if you've only 1 name field:

select p.name, m.phonenumber
from abperson p
inner join abmultivalue m
on p.personid = m.personid

by wizard-09

shellbot, looked at what you wrote mod it to my needs and worked a treat thanks for the help and info ;)

This discussion is closed to new replies.