Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:19:00+00:00 2026-06-14T10:19:00+00:00

I am trying to write a SQL query in Delphi, but yet without luck.

  • 0

I am trying to write a SQL query in Delphi, but yet without luck.

I have two tables, the first one holds personal data, the second one holds information about purchased goods.

My query works fine when I connect the two tables with WHERE clause (my key is person_id).

But I would like to add records to my query that have no personal data, just someone purchased the goods, they don’t display.

So in those records where there isn’t any personal information I need to have empty strings or null values.

Is it possible to do in one SQL query?

Edit: Here is the working version, but this doesn’t contain the second table’s values that are not related to the first table.

Query1.SQL.Add ('SELECT idcard, vnev, knev, kapcs, ');
Query1.SQL.Add ('bsz, bt, kidate, ervvege, alkalmak FROM "'+adathely+'", "'+berlethely+'" ');
Query1.SQL.Add ('WHERE ("'+adathely+'".idcard = "'+berlethely+'".idcard) ');
//from here only filtering occurs
Query1.SQL.Add ('AND kidate >= "'+IntToStr(DateToInt(filterdate1.Text))+'" ');
Query1.SQL.Add ('AND ervvege <= "'+IntToStr(DateToInt(filterdate2.Text))+'" ');
Query1.SQL.Add ('AND CAST(bsz AS CHAR(6)) LIKE '''+filterbsz.Text+'%''  ');
Query1.SQL.Add ('AND ((LOWER(vnev) LIKE ''%'+filtername.Text+'%'') OR (LOWER(knev) LIKE ''%'+filtername.Text+'%''))  ');
Query1.SQL.ADD ('ORDER BY vnev ASC ');

A little explanation: table1 is “adathely” table2 is “berlethely”
Both tables contain the field ‘idcard’, but in table2 there are records that do not have value in this field, but i also would like to display them in my stringgrid.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:19:01+00:00Added an answer on June 14, 2026 at 10:19 am

    I think you wrote a query like this:

    SELECT *
    FROM Table1, Table2
    WHERE Table1.person_id = Table2.person_id
    

    and if person_id is present in Table1 but not in Table2, no record will appear.

    Try a LEFT JOIN instead:

    SELECT *
    FROM Table1 LEFT JOIN Table2 on Table1.person_id = Table2.person_id
    

    This will show every record in Table1 even if it is not correlated to a record in Table2.

    EDIT: if a left join is not enough, you probably need a FULL OUTER JOIN. If your DBMS does not support FULL OUTER JOIN, you could simulate it using this:

    SELECT *
    FROM Table1 LEFT JOIN Table2 on Table1.person_id = Table2.person_id
    UNION SELECT *
    FROM Table1 RIGHT JOIN Table2 on Table1.person_id = Table2.person_id
    

    and since there are a lot of conditions in the where clause, i’d suggest you to write your query like this:

    SELECT *
    FROM (the union query above) tables
    WHERE ...all the conditions,
      except table1.idcard = table2.idcard that's already included in the join...
    

    just to make things more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a SQL Server query but have had no luck
I have a SQL query that I'm trying to write, but I'm not quite
I'm trying to write a sql query that shows how often two teams have
I am trying to write a SQL query where I am joining two tables
I'm fairly new to SQL, but trying to write quite a complicated query, but
i'm having a bit of trouble trying to write an sql query. i have
I am trying to write a sql query but i find some difficulties.What i
I am trying to write a SQL statement between two tables where there is
OK trying to write a SQL query to a text file. I have tried
I am trying to write a SQL query that pulls from 3 tables and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.