0

I've mysql one table with two field object1 and object2. A separate query search result by typing in ID on input form only any ID that match object1 with 222 and 333 will return a query result of a same row of the ID.

The same for object2 by typing ID that match with object2 with 444 and 999 will return a query result of a same row of the ID.

For example, type in 12345 in input form and a result will show Joe Long object1 (instead of 222)

Can anyone think of sql and php please?

For example if I search by ID 12345 then I want get result as Joe Long, object1.

 +-----------------------------------------------------------------+
 | ID        | firstName   | lastName | object1 | object2 | sortID |
 +-----------------------------------------------------------------+
 | 12345     | Joe         | Long     |  222    |    444  |   66   |
 | 12346     | John        | Higgins  |  222    |    444  |   66   |
 | 12347     | David       | Crowe    |  333    |    444  |   66   |
 | 12348     | Denise      | Jacob    |  333    |    999  |   77   |
 | 12349     | George      | Jacob    |  333    |    999  |   77   |
 | 12350     | Iain        | Jacob    |  111    |    444  |   66   |
 | 12351     | Kevin       | Dalglish |  888    |    555  |   77   |
 | 12352     | Christina   | Brown    |  888    |    555  |   77   |
 | 12353     | Jean        | Scholes  |  888    |    555  |   66   |
 | 12354     | Angela      | Scholes  |  333    |    555  |   77   |
 | 12355     | Ellie       | Scholes  |  333    |    555  |   77   |
 +-----------------------------------------------------------------+
2
  • 2
    so, you-wish-to-hire-a-programmer-for-you? Commented Apr 24, 2012 at 23:03
  • I can only wish and I need to learn. Commented Apr 24, 2012 at 23:06

1 Answer 1

1

Probably something like:

select *
from `table`
where object1 like '%query%' or object2 like '%query%'
group by ID 
order by sortID asc
Sign up to request clarification or add additional context in comments.

2 Comments

Ok Zenbait. Does this will return as Joe Long object1 (instead of 222) for one person?
Is it possible to narrow it down to object1 222 and 333 for if a user type in a ID 12345 and Joe Long will appear as a result? The same for object2 444 and 999 if a user type ID 12350 and Iain Jacob will show as a result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.