Jump to content

[SOLVED] Complex query help


Web_dev_06

Recommended Posts

Hello everyone,

 

  I am not a SQL expert, and need help structuring a real complex query -at least to me- here are the details:

 

- Table A contains usernames and ID's (the ID's is not unique, the primary key is a third column not important

    here) So, here is an example:

        A

      ------------------

      username          x      y

      id                    2      2

 

- Table B consists of many columns, but, the ones important here are: id and Data Name

  So, here is an example

        B

    --------------------

      id                      2 

      Data Name        Test 

 

- Here is what I have:

      username  (from table A)

      Data Name  (from table B)

          (you might already know what is needed by now)

- What I need:

          1- ID of table A match the username

          2- Query table (B) and query against the Data Name

          ==> Return the single row matching 1 & 2

am looking forward for your help.

               

Link to comment
https://forums.phpfreaks.com/topic/45773-solved-complex-query-help/
Share on other sites

SELECT A.id,B.data_name FROM A,B WHERE A.id=B.id AND username='...' AND data_name='...'

 

It's not a complex query, just a complex description.  :-)  Actually you won't need to return the data name if you already know it in the WHERE clause.  Was that what you're looking for?

Absolutely,

 

 

  Thanks so much. you are right, I made it complex, and here is the query used to solve the problem (very similar to yours-

 

  SELECT e.id, i.id

  FROM A e, B i

  WHERE e.DataName = 'Test'

  AND e.id = i.id

  LIMIT 0 , 50;

 

Appreciate the fast response.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.