force table alias in complex select

force table alias in complex select

Postby elvira » Sat Jul 20, 2013 2:59 pm

Dear Friends,

I have three tables where a field called Registro exists on two of them.

This select Works fine in Access:

"SELECT * FROM PRESTAMOS, LIBROS, LECTORES WHERE PRESTAMOS.REGISTRO = LIBROS.REGISTRO AND PRESTAMOS.REG_USUARI = LECTORES.REG_USUARI" )

Access converts first REIGSTRO from PRESTAMOS Table as PRESTAMOS.REGISTRO.

The same with REGISTRO at LIBROS Table, converted as LIBROS.REGISTRO.


But MySQL does not do such conversión. The resulting Recordset has a field REGISTRO twice.

How can I forcé MySQL to work the same as Access please?:

Thank you very much.
elvira
 
Posts: 516
Joined: Fri Jun 29, 2012 12:49 pm

Re: force table alias in complex select

Postby Enrico Maria Giordano » Sat Jul 20, 2013 3:20 pm

Elvira,

elvira wrote:Dear Friends,

I have three tables where a field called Registro exists on two of them.

This select Works fine in Access:

"SELECT * FROM PRESTAMOS, LIBROS, LECTORES WHERE PRESTAMOS.REGISTRO = LIBROS.REGISTRO AND PRESTAMOS.REG_USUARI = LECTORES.REG_USUARI" )

Access converts first REIGSTRO from PRESTAMOS Table as PRESTAMOS.REGISTRO.

The same with REGISTRO at LIBROS Table, converted as LIBROS.REGISTRO.


But MySQL does not do such conversión. The resulting Recordset has a field REGISTRO twice.

How can I forcé MySQL to work the same as Access please?:

Thank you very much.


This works at least on Access, MSSQL and MySQL:

Code: Select all  Expand view
"SELECT * FROM PRESTAMOS AS T1, LIBROS AS T2, LECTORES AS T3 WHERE T1.REGISTRO = T2.REGISTRO  AND  T1.REG_USUARI = T3.REG_USUARI"


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8400
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: force table alias in complex select

Postby elvira » Sat Jul 20, 2013 5:04 pm

Mr. Enrico,

It Works in Access but it still does not work with MySQL.

If I do an xBrowse, I see the same fields with no tx, even on registro field.

Thaks.
elvira
 
Posts: 516
Joined: Fri Jun 29, 2012 12:49 pm

Re: force table alias in complex select

Postby Enrico Maria Giordano » Sat Jul 20, 2013 5:16 pm

Elvira,

elvira wrote:Mr. Enrico,

It Works in Access but it still does not work with MySQL.

If I do an xBrowse, I see the same fields with no tx, even on registro field.

Thaks.


All I can say is that I'm using that syntax with MySQL without problems. Do you get any error messages?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8400
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: force table alias in complex select

Postby nageswaragunupudi » Sat Jul 20, 2013 7:32 pm

The issue raised by Mr Elvira is different.
You will get duplicate column names when you use SELECT * , unless you specify every column and provide unique alias column name for the duplicated column names, in all DBMS expect MSACCESS.

It is highly desirable to avoid duplicate field names by laboriously specifying all field names in the select clause. Sad no DBMS, except MSACESS provides this automatic feature.

Any way, provided you do not make it a habit, you can tolerate the duplicate field names in the recordset and it does not hurt you much if you take some precautions like refer to fields by number and not by name. Eg: oRs:Fields(0):Value and not oRs:Fields( "name" ):Value

Each field contains in its properties collection the real field name in the table and the basetable from which the field is read. Recordset does not get confused.

That brings me to the point that xbrowse does get confused. XBrowse reads and writes fields by names ( eg. oRs:Fields( "name" ):Value := uNewVal )
It is high time I make some suitable changes.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10317
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: force table alias in complex select

Postby Enrico Maria Giordano » Sat Jul 20, 2013 9:18 pm

NageswaraRao,

nageswaragunupudi wrote:The issue raised by Mr Elvira is different.
You will get duplicate column names when you use SELECT * , unless you specify every column and provide unique alias column name for the duplicated column names, in all DBMS expect MSACCESS.


Ok, I didn't understand. You can use

Code: Select all  Expand view
SELECT *, PRESTAMOS.REGISTRO AS PREREG, etc. FROM ...


nageswaragunupudi wrote:It is highly desirable to avoid duplicate field names


I agree.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8400
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Otto and 135 guests