0

I would like to display on a TDbgrid data from 2 tables on a single database file. I have tried to write sql statements like:

select "Client", "Address", "Balance" from "table1"
and "Payment" from "table2"

But it always shows this error

SQL Error: Dynamic SQL Error DQL Error code = -104 Token Unknown - line 2,
column1 and.Error -104.Invalid token The SQL: select "Client", "Address", "Balance"
from "table1"
and "Payment" from "table2" 

I don't know if it is not possible or I just got error on writing the code or is it the TDbgrid I need to modify. I searched for a zeos sql guide but I cannot find one. All I got was this: http://www.intitec.com/varios/A_ZEOS_basics_tutorial_not_only_for_firebird.pdf but still some of my questions are left unanswered.

I am using firebird database 2.5 and delphi 7.

What SQL code can I use on this?

Chunk Chunk
  • 143
  • 6
  • 17
  • 2
    "shows an error" doesn't mean anything unless you tell us **what the error is**. I'm not sure how many times you need to have this explained to you. **Be specific** when you ask questions here. (Your syntax is invalid; you should search Google for a tutorial in basic SQL.) – Ken White May 05 '13 at 04:45
  • Edited my question. I have read some basic SQL tutorials, but the problem is that I cannot find one for ZEOS. I don't know which sql command will work on it. I just wanted to display the columns from 2 tables in a single TDdgrid. – Chunk Chunk May 05 '13 at 04:56
  • Basic SQL is basic SQL. The fact it's Zeos doesn't matter. Google `SQL tutorial`. – Ken White May 05 '13 at 04:59
  • I edited my question again. I want to display some columns on table 1 and 2. – Chunk Chunk May 05 '13 at 05:04
  • Make up your mind what you want to ask, and then ask it. Changing the question again and again makes it hard to answer. It's much harder to hit a moving target, and changing the question after it's been answered makes the answers to the previous question look foolish (and wrong). – Ken White May 05 '13 at 05:07
  • Sorry for that, I just got confused in posting my question because I am always nervous when I click the question button on this site. I also tried this: select "BALANCE" from "BALANCE" , "CLIENT_NAME" FROM "CLIENT", "PAYMENT" FROM "COLLECTION" and it returned the invalid token error again. – Chunk Chunk May 05 '13 at 05:10
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29428/discussion-between-chunk-chunk-and-ken-white) – Chunk Chunk May 05 '13 at 05:12
  • There's no need to continue this in chat. I've answered your question, and I'm not going to provide you with a private tutorial in SQL. As I said, Google "SQL tutorials". This is basic information you need to learn if you're going to work with databases (in Delphi or not). – Ken White May 05 '13 at 05:18

2 Answers2

7

Your syntax is invalid.

SELECT * FROM table1, table2

However, the above doesn't make sense either, as you're selecting every column and row from two separate tables with no means of connecting the two tables.

Table1
ColumnA    ColumnB
=======    =======
Nonsense   Here
Orange     Noise

Table2
ColumnC    ColumnD
=======    =======
Horse      Radish
No         Sense

SELECT * FROM Table1, Table2

Result:

ColumnA    ColumnB    ColumnC    ColumnD
=======    =======    =======    =======
Nonsense   Here       Horse      Radish
Orange     Noise      No         Sense

Even after your edit, there's no sense in the query.

SELECT Table1.ColumnA, Table1.ColumnB, Table2.ColumnC, Table2.ColumnD
FROM Table1, Table2

still yields the same results.

You really should look for tutorials on database programming and SQL in general. Google can help.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Got it working now. Thank you very much for your great help and guidance. – Chunk Chunk May 05 '13 at 05:30
  • Personally, I prefer the SQL-92 `JOIN` syntax over this one (the SQL-89 variant). – Mark Rotteveel May 05 '13 at 16:12
  • @Mark: So would I, but the poster provided no information on which to base a join. It's an ongoing issue with this poster (leaving out necessary info); look at some of his other questions. – Ken White May 05 '13 at 17:42
1

I just got some invalid syntax on my SQL statement. And this solved my problem

SELECT Table1.ColumnA, Table1.ColumnB, Table2.ColumnC, Table2.ColumnD
FROM Table1, Table2

Thank you very much.

Chunk Chunk
  • 143
  • 6
  • 17