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
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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.