1

I have this MySQL Structure:

CREATE TABLE Fields (
ID INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
ForUser VARCHAR(255) NOT NULL,
ForCategory VARCHAR(100) NOT NULL,
FieldName VARCHAR(100) NOT NULL
);
CREATE TABLE Content (
ID INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
ForUser VARCHAR(255) NOT NULL,
ForCategory VARCHAR(100) NOT NULL,
ForField VARCHAR(100) NOT NULL,
FieldContent VARCHAR(255) NOT NULL
);

Now I want to make SQL Query that list results. Query must list content from 'Fileds' and must list content from 'Content' for specific Field. That will look like this:

FieldName > ID 1(Table:Fields) -Content > ID 1(Table:Content) -Content > ID 2(Table:Content)... FieldName > ID 2(Table:Fields) -Content > ID 1(Table:Content) -Content > ID 2(Table:Content)...

5
  • Are you sure a SQL join will produce HTML for you? Commented Jul 10, 2015 at 16:28
  • No. I need SQL Query that will give me joined results from tables Commented Jul 10, 2015 at 16:30
  • 1
    Could you then remove the references to HTML? And possibly add an example output table. Commented Jul 10, 2015 at 16:33
  • I'm going to have to agree with @dezso here and would like you to add maybe an example of what you have so far. Anything you could add to make it so we can understand enough to help you.
    – Zane
    Commented Jul 10, 2015 at 17:13
  • I have edited post with new data and example Commented Jul 10, 2015 at 17:44

1 Answer 1

1

According with your last edit:

SELECT
    F.*,
    C.*
FROM db1.Fields AS F
JOIN db1.Content AS C ON (C.ID = F.ID AND C.ForUser = F.ForUser 
                          AND C.ForCategory = F.ForCategory)
WHERE `the field you want to filter`=`the value you want to search`;

You can filter with Any field in Fields or Content.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.