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 8020371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:40:38+00:00 2026-06-04T21:40:38+00:00

Here is an example to explain what I need: I have 3 tables: contact:

  • 0

Here is an example to explain what I need:

I have 3 tables:

 contact: { id, invoices, name } // a contact can have several invoices
 invoice: { id, contact, lines, comment } // an invoice can have several lines but only one contact
 line: { id, invoice, designation } // a line can have only one invoice

If a user search an invoice, a want to query the comment, designation and name fields and getting only the invoice that match.

So I’ve done this:

SELECT 
  invoice.id AS id, 
  invoice.contact AS contact, 
  invoice.comment AS comment, 
FROM invoice 
  LEFT JOIN contact ON invoice.contact = contact.id 
  LEFT JOIN line ON line.invoice = invoice.id
WHERE (
  contact.name LIKE '%SEARCH_TERM%' OR 
  invoice.comment LIKE '%SEARCH_TERM%' OR 
  line.designation LIKE '%SEARCH_TERM%'
)

This work except that if an invoice has several lines which match the search term, I will get several times the same invoice.

So my question is: is there a way to get only once an invoice even if the search term is find in several related records ?

Also, is there a way to get only the fields of the invoice without using ALIAS (I don’t care about the tables contact and line except for the search) ?

If you know a better way to do that, I’d love to hear it.

  • 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-04T21:40:39+00:00Added an answer on June 4, 2026 at 9:40 pm
    SELECT 
      DISTINCT invoice.*
    FROM invoice 
      LEFT JOIN contact ON invoice.contact = contact.id 
      LEFT JOIN line ON line.invoice = invoice.id
    WHERE (
      contact.name LIKE '%SEARCH_TERM%' OR 
      invoice.comment LIKE '%SEARCH_TERM%' OR 
      line.designation LIKE '%SEARCH_TERM%'
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To better explain what I need I uploaded an example here . I have
Can someone explain, how can I avoid application freezing when I, for example, have
Before I explain, here's the example HTML code : [ Demo on jsFiddle here.
Here an example my database structure.. uid email name ------------------------------- 1 john@gmail.com John 2
Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
Example here: http://jsfiddle.net/KyW6c/2/ I have an ordered list. Each list item is a project
I probably won't be able to explain this well enough, but here it goes...
I guess I don't give title nicely, anyways, I can explain it better here:
I have several encoded strings and I need to decode them, my guess is
I have 3 different transaction tables, which look very similar, but have slight differences.

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.