SQL server , Add data in multi value attribute [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table Photos with attribute comments
i want to declare that comments take many values
and want to know how to insert a new value to it

You should probably have a column photo_id in your comments table. This would let you have a lot of comments for each photo.
The way you are saying it, it would let you have the same comment in different photos, but that looks less likely to be what you really want.
Something like this:
photos:
id primary key
comments
id primary_key
photo_id foreign_key referencing photos(id)

Related

finding the word like in a sql query [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string like this:
i would like to go to office, and i would like to go to market
My question is: how many times the word like occurs in the string?
Please write a query.
You can use regexp_count:
SELECT REGEXP_COUNT('i like to go , and i would like market', 'like')
FROM DUAL;
The word "like" occurs twice in the string you posted.
The following is a query:
SELECT *
FROM SOME_TABLE
WHERE SOME_VALUE = SOME_OTHER_VALUE
Share and enjoy.

Recursive sql query for webpage URL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm using postgresql but if there's a generic sql way even better.
I have a table storing data for webpages, including slug (e.g. in example.com/x/y, x and y are both slugs) and parent_id (x and y each have a record in this table. x's id matches y's parent_id).
If I have the id for y, is there an easy way to find out the full URL (/x/y)? Or at least all the id's (/x_id/y_id)?
I know that I can get this for this particular example like this:
select parent_id from pages where slug like 'x';
=> 5
And get the slug for that id:
select slug from pages where id = (select parent_id
from pages where slug like 'x');
=> y
But what if the URI was more like /a/b/c/d/e/f/g? Is there an easy way to find all of that if all I have is the id for g?
As #a_hourse-with_no_name said a recursive CTE should take care of you. This is my favorite link for CTE's: CTE Basics

How to be a command in SQL using LIKE? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to select records where a field (varchar (45)) contains one and only one letter x and the field length is greater than 20
In MySQL you can do:
SELECT * FROM tablename WHERE fieldname REGEXP '^[x]{20,}$'

How to display following display table using oracle? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Link http://s17.postimg.org/pdftjpl1r/Event.png
I have above two table.I want to display third table using oracle. I know display those data using java,vector and other stuff.But couldn't code correct oracle code.In the above display table shows data which are >=SYSDATE.
I think it is something like this:
select e.event_name,
min(dt.start_date) as start_date,
min(dt.start_date)||'-'||max(dt.end_date) as FromTo
from event e join
date_table dt
on e.e_id = dt.e_id
group by e.event_name;
You may need use to_char() to convert date/times to the right format. You don't specify wht the types are in the data, so it is hard to say what needs conversion.

Get me a SQL quesry to check whether the two table data contents are equal? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am having two table A and B of same structure.Both tables is loaded with data.I just want the mismatched row of two tables.,,
I'm certain you could do some gigantic JOIN query for each column and then issue a NOT IN over the result but a simple, pragmatic solution is to:
Write a query that orders the data on several columns (or all)
Export the query executed on each table to a separate text file
Use diff to compare the files with each other
Depending on the RDBMS vendor you may have other options you could consider as well.