MySQL joined select

Ken Ray kray at sonsothunder.com
Tue Mar 20 11:46:19 EDT 2012


On Mar 20, 2012, at 4:20 AM, Marek Reichenbach wrote:

> Thanks for the replies.
> I've made it workin, but I wanna add something else:
> 
> So the question in SQL is:
> 
> Maybe there is a way to hide columns it the result, like:
> SELECT car_nr, model, travel_days FROM table1,table2 WHERE number <> 414
> AND (car_nr > truck_nr) from transport;
> and show only result of the colums travel_days, but ONLY on*
> **separate* columns
> and  HIDE OTHER COLUMNS.

You only include the columns you want back in the SELECT part of the query:

SELECT travel_days FROM …

Also, although I know you provided a dummy query, be aware that there are two inherent problems with the one you provided:

1) If you have multiple tables in the FROM clause, you need to identify the table attached to the column in the SELECT clause (although some SQL engines might just assume you meant the first table, it's good form to identify the table), either by full name:

  SELECT table1.travel_days FROM table1,table2 WHERE…

or by alias:

  SELECT t1.travel_days FROM table1 t1,table2 t2 WHERE…

2) I'm not sure what "from transport" means since you already have a FROM clause in your example query

The bottom line is that you don't have to include columns in the SELECT portion of the query that you don't want back, so long as you identify them properly and they actually exist in the table you're referencing.

Just be aware that LiveCode's text parsing is second to none, so there are usually times where it may actually be easier and more efficient to let SQL handle getting the data, but let LiveCode handle parsing the data after it arrives. As I mentioned in an earlier post, you *can* use SQL to change your numbers to "+" symbols, but it's ugly - Mark's method to post-process it in LC with a single statement if far better (IMHO).

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/	




More information about the use-livecode mailing list