How to get ID column data back to Livecode

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

How to get ID column data back to Livecode

Post by ECNU4271 » Fri Aug 30, 2013 4:18 pm

Hi, all!

When using "SELECT * FROM tTableName"

all data from that table are being retrieved.

My concern is How to get the ID column back from the database.

The ID column is just the most left column in the DB, recording 1,2,3,4,5...


Is there a sentence to retrieve that information?

Thanks a lot,
Michael

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to get ID column data back to Livecode

Post by Klaus » Fri Aug 30, 2013 4:30 pm

http://forums.runrev.com/phpBB2/viewtop ... 437#p84437
Replace "Password" with "ID" (No quotes!) and leave out the "WHERE" stuff!
8)

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: How to get ID column data back to Livecode

Post by bangkok » Fri Aug 30, 2013 6:33 pm

ECNU4271 wrote: My concern is How to get the ID column back from the database.

The ID column is just the most left column in the DB, recording 1,2,3,4,5...
I'm not really sure to understand your question...

Are you talking about the name of the column that contains those ID ?

If it's for instance "theid" then you can use a SQL query such as :

Code: Select all

SELECT theid FROM tTableName

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to get ID column data back to Livecode

Post by ECNU4271 » Fri Aug 30, 2013 8:26 pm

Klaus wrote:http://forums.runrev.com/phpBB2/viewtop ... 437#p84437
Replace "Password" with "ID" (No quotes!) and leave out the "WHERE" stuff!
8)
NONO, ID is not a column that I name it "ID" .

As I said, in the database, the most left column is the ID column

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to get ID column data back to Livecode

Post by Klaus » Fri Aug 30, 2013 8:34 pm

You mean the "Primary Key" http://www.w3schools.com/sql/sql_primarykey.asp?
Sorry, no idea how to retrieve this if you did not define a "primary key" database field.

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to get ID column data back to Livecode

Post by ECNU4271 » Fri Aug 30, 2013 8:51 pm

When checking data of the table in MySQL

Table: (I only create Name, Password, Gender, Age)

ID Name Password Gender Age
1 Jack 123456 Male 19
2 Mary 123455 Female 18
3 Michael 123454 Male 20
4 ..
5 ..
6 ..

In this case, if I use "SELECT * FROM tTableName"

I'll get :
Name Password Gender Age
Jack 123456 Male 19
Mary 123455 Female 18
Michael 123454 Male 20
..
..


What I want is to get exactly what I can see from the database (includes ID column which is created by MySQL ifself)
ID Name Password Gender Age
1 Jack 123456 Male 19
2 Mary 123455 Female 18
3 Michael 123454 Male 20
4 ..
5 ..
6 ..

So in this case, is ID the primary key?
and how can I achieve that?

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: How to get ID column data back to Livecode

Post by bangkok » Fri Aug 30, 2013 9:47 pm

Ah ah ah I got it now.

The number you are talking about... are just displayed by your MySQL client software (like Excel), line per line.
:)

Right ?

So to do what you want (to see a unique number for each record) you need to add a column to your database.

Currently you have :
Name, Password, Gender, Age

Add one column : myid (see screenshot)

-give it the type like INT

-give it the "AUTO INCREMENT" default

-make it the primary key (check if primary key is not already set on the column "name" for instance)
Attachments
MYSQL.png

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to get ID column data back to Livecode

Post by ECNU4271 » Fri Aug 30, 2013 10:44 pm

aha

great, thanks Bangkok!

Post Reply